views:

517

answers:

1

I have an NServiceBus application for which a given message may not be processed due to some external event not having taken place. Because this other event is not an NSB event I can't implement sagas properly.

However, rather than just re-queuing the message (which would cause a loop until that external event has occurred), I'm wrapping the message in another message (DelayMessage) and queuing that instead. The DelayMessage is picked up by a different service and placed in a database until the retry interval expires. At which point, the delay service re-queues the message on the original queue so another attempt can be made.

However, this can happen more than once if that external event still hasn't taken place, and in the case where that even never happens, I want to limit the number of round trips the message takes. This means the DelayMessage has a MaxRetries property, but that is lost when the delay service queues the original message for the retry.

What other options am I missing? I'm happy to accept that there's a totally different solution to this problem.

+2  A: 

Consider implementing a saga which stores that first message, holding on to it until the second message arrives. You might also want the saga to open a timeout as well so that your process won't wait indefinitely if that second message got lost or something.

Hope that helps. -- Udi Dahan

Udi Dahan
Wow the man himself - thanks! I can't really use a saga I don't think. There is only one message, and it needs some data in the database before it can be processed. There aren't actually two messages that I can assemble into a saga, the data is created by a legacy stored procedure, I'm using NSB to add additional data that references it.
Neil Barnwell
Then use the timeout in the saga to check if there was data in the database - it'll provide you a simple polling mechanism; no data, request another timeout.
Udi Dahan