I wrote consumer using MassTransit and using Azure Service Bus as transport.
public async Task Consume(ConsumeContext<ISimpleRequest> context)
{
try
{
_log.InfoFormat("Strated working on {0}", context.Message.CustomerId);
Thread.Sleep(500);
_log.InfoFormat("Returning name for {0}", context.Message.CustomerId);
}
catch(Exception ex)
{
await context.Redeliver(TimeSpan.FromSeconds(1));
}
}
I redeliver message to another consumer if exception happens.
But what happens if bus sends a message, the consumer starts working on it and process is shut down? How can I not lose the message?
Redeliverin your exception handling. You would be better off using a retry policy, and then if it still fails allow the exception to fault the consumer. - stuartd