Search code examples
nservicebusnservicebus-sagas

How to make Saga message Handle wait for another Handle to complete in NService Bus


We recently started implementing Nservice bus in our project. We are new to Saga Service and we are struck with the below scenario.

Assume like, we have 4 steps in our saga and saga will be started by message1.

Message 2 will be triggered by some external services. We have to process the message2 one and only after the message1 processing is completed which can run for long time.

How can we accomplish this? Other than using Thread.Sleep on message2 handle or something like having common method which will be called on message 2 arrival after checking for message1 completion and at the end of message 1 processing after checking the message 2 arrival.

We are not using Service Matrix.

Thanks in advance.


Solution

  • You can use the timeout feature to do something like:

    when the handler for message2 is invoked, check if message1 had completed (property in your saga data)

    • if message1 didn't complete call a RequestTimeout

    when the timeout handler is invoked:

    • if message1 is complete send a message to a handler that does the unit of work for message2

    • if message1 did not complete do another RequestTimeout until message1 is complete processing

    I would strongly advice against doing anything like thread sleep

    Dose that make sense?