1

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.

Venkat
  • 853
  • 10
  • 26

2 Answers2

1

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?

Sean Farmar
  • 2,254
  • 13
  • 10
0

I would implement your second suggestion. This is similar to the approach we have been taking.

So in your SagaData you would have one status flag that indicate whether Message1 has been successfully processed and another status flag indicating whether Message2 has been received, also storing any properties needed to process Message2.

At the end of Message1 handler and after the property-storing part of the Message2 handler you would call a common method which checks the status flag for both messages, continuing the Message2 processing if both status flags are set.

Svein Fidjestøl
  • 3,106
  • 2
  • 24
  • 40