1
votes

We use rebus and Sqs for messaging. We also have configured on each queue a Redrive policy moving the messages to a DeadLetter queue after 3 retries. We have many handlers handling the same message type:

public class MessageHandlerA : IHandleMessages<MessageX>
{
    public async Task Handle(MessageX message)
    {
        Console.WriteLine("HandlerA is about of failing");
        throw new FileLoadException();
    }
}

public class MessageHandlerB : IHandleMessages<MessageX>
{
    public async Task Handle(MessageX message)
    {
        Console.WriteLine("HandlerB finished Ok");
    }
}

The behavior here is that rebus aborts the Handling pipeline after the first handler fails. We are using a deadletter queue. When a handler raises an exception the message goes to the deadletter queue (expected behavior). The thing here is that we want to track what handlers have processed the message and what handlers dont for avoiding the same handler to process the message twice after the message is reprocessed from DeadLetter queue.

1

1 Answers

1
votes

If your handlers can succeed/fail individually, and they are not somehow enlisted in a transaction that can be rolled back on exceptions (e.g. like a SqlTransaction shared by all handlers), you should not rely on the message handler pipeline do "do multiple things" for one message.

You should probably receive your MessageX in a handler that sends two messages to itself, this way using individual messages for each thing that should be done.