Dead letter queues in RabbitMQ
11 Nov 2026 · Messaging · by Ikbal Mulyadi
A dead letter queue holds the messages that a consumer could not process. It keeps them out of the main queue and lets you examine each failure.
When RabbitMQ dead-letters a message
RabbitMQ moves a message to the dead letter exchange in three cases:
- A consumer rejects the message and does not requeue it.
- The message time-to-live expires.
- The queue reaches its length limit.
The exchange then routes the message to the queue that you bind to it.
Set a dead letter exchange
Name the dead letter exchange when you declare the queue. This example uses the amqplib client for Node.js.
await channel.assertExchange('orders.dlx', 'fanout');
await channel.assertQueue('orders.dead');
await channel.bindQueue('orders.dead', 'orders.dlx', '');
await channel.assertQueue('orders', {
deadLetterExchange: 'orders.dlx',
});
Track failed messages
Each dead-lettered message has an x-death header. The header records the queue, the reason and the count. Log these values, and set an alert on the length of the dead queue.