Question

I created a saga with NServiceBus that request external service for customer's information and make timeout. After timeout expire that saga check if external service has response. In response I have data of corresponding customers and now I have situations where I must check if that corresponding customer exists in our system (if he doesn't - I must create him) after that I must create some additional audit entity that refer to that customer (if I have all needed information to create them).

I wonder how i should check if a specific customer exists and when not how to create him.

I have a few ideas so far:

  • invoke WCF service from inside the message handler (check, create)

  • send message via NSB to Customer bounded context and wait for response with ID.

Was it helpful?

Solution

You could leverage the NServiceBus message handling pipeline for this. Have a handler from your "Customer Service" configured to run first, which checks for the existence of the customer and creates them if necessary, finally setting the CustomerID property on the original message being handled so that the next handler will know what it is.

This gives you the benefit of transactional consistency around the whole process.

The publish/subscribe model you described could also work. I don't like it as much because you 're going into a kind of request/response over events and it isn't clear who is really responsible for the customer info (as the data needed is coming from a publisher not responsible for the customer).

It's hard to be more prescriptive without going in depth into your domain.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top