Question

If I have a saga that consists of two message types, say started by message1 and completed by message2, can I return a callback if a message2 comes in without a message1 already existing? I know it will dump it in the error queue, but I want to be able to return a status to the sending client to say there is an error state due to the first message not being there.

Was it helpful?

Solution

So I figured it out, I just needed to implement IFindSagas for the message type:

public class MySagaFinder : IFindSagas<MySagaData>.Using<Message2>
{
    public ISagaPersister Persister { get; set; }
    public IBus Bus { get; set; }

    public MySagaFinder FindBy(Message2 message)
    {
        var data = Persister.Get<MySagaData>("MessageIdProperty", message.MessageIdProperty);
        if (data == null)
        {
            Bus.Return(0);
        }
        return data;
    }
}

I don't know if this is the right way to do it, but it works!

OTHER TIPS

If you have a saga that can receive two messages, but messages can be received in any order, make sure the saga can be started by both messages. Then verify if both message have arrived by setting some state in the saga itself. If both messages have arrived, mark it as complete.

Default NServicebBus behavior is to ignore any message that has no corresponding saga. This is because you can set a timeout, for example. If nothing happens within 24 hours, the saga can send a Timeout message to itself. But if something did happen and you marked your saga as being completed, what should happen to the Timeout message? Therefor NServiceBus ignores it.

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