views:

92

answers:

1

I have an NServiceBus Saga that looks like this

public class MySaga : Saga<MySagaData>,
                                IAmStartedByMessages<MyStartMessage>,
                                IHandleMessages<OtherMessage>

But messages can come out of order. So what happens when the IAmStartedBy Message comes after the IHandle Message? There will be no SagaData for OtherMessage. Will NServiceBus swallow the message or try to re-handle it later?

+1  A: 

NServiceBus will fail to find an active saga for OtherMessage, retry the configured number of times and then put the message in the error queue. The retries might delay long enough for MyStartMessage to arrive. Any reason why OtherMessage can't start the saga as well? (you can have multiple messages that can start a saga)

Andreas
Andreas. This was the answer ie expected. I wanted to avoid having multiple IAmStartedByMessages because that complicates the code for each handler.
Simon
One of the usage areas for Sagas is to handle situations like yours where messages can arrive out of order so I wouldn't be to concerned about having multiple IAmStartedBy. Good luck!
Andreas