Skip to content

DeadLetter

derekgreer edited this page Jun 1, 2012 · 4 revisions

When consuming messages with RabbitMQ, messages can be rejected with an option to requeue the message for the next consumer or to have the message discarded. When you choose to reject a message without having it requeued, RabbitBus can be configured to publish the message to a deadletter queue.

The following configuration will publish rejected messages to a queue named "deadletter" bound to the default exchange:

_bus = new BusBuilder()
	.Configure(ctx => ctx.WithDeadLetterQueue()
			.Consume<StatusUpdate>()
				.WithExchange("status-update-exchange")
				.WithQueue("status-update-queue"))
	.Build();

RabbitBus also supports the ability to publish messages to a custom deadletter queue by using an overload of the WithDeadLetterQueue() method which accepts a queue name:

_bus = new BusBuilder()
	.Configure(ctx => ctx.WithDeadLetterQueue("custom-deadletter-queue")
			.Consume<StatusUpdate>()
				.WithExchange("status-update-exchange")
				.WithQueue("status-update-queue"))
	.Build();

##Note## In the event an error occurs during the dequeuing of a message, RabbitBus will automatically publish the message to the default deadletter queue on the default exchange.

Clone this wiki locally