Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How does dead-lettering work in RabbitMQ, and which events cause a message to be dead-lettered?

A queue gets a dead-letter exchange through the x-dead-letter-exchange argument or a policy, optionally with x-dead-letter-routing-key. RabbitMQ then republishes a message to that exchange when it is rejected or nacked with requeue=false, when its TTL expires, or when the queue's length limit pushes it out, and quorum queues also dead-letter when a message exceeds the delivery limit. The broker adds an x-death header recording the reason, the queue and a count, and the dead-letter exchange routes the message to a dead-letter queue like any other exchange.

Why this question is asked

Every production queue needs an answer to the question of what happens to a message that cannot be processed. Without one, failed messages are either dropped silently or retried forever. Dead-lettering is RabbitMQ's answer, and because it is built from ordinary exchanges and queues, it is also the basis of retry delays and parking queues. Interviewers ask this to check the configuration, the exact events that trigger it and the metadata the broker adds. In this answer, we will recap the idea, configure a dead-letter exchange, go through each event that dead-letters a message, look inside the x-death header, and finish with how the dead-lettered message is routed.

1A Quick Recap: What Dead-Lettering Means

A dead letter is a message that its queue gives up on. Instead of deleting it, RabbitMQ can republish it to another exchange, the dead-letter exchange, often called a DLX. From there it is routed like any published message, usually to a dead-letter queue where it waits for a person or a tool to look at it.

Dead-lettering is configured on the queue, not on the message or the producer. The producer does not know or care; it is the queue that decides what to do with messages it can no longer keep.

2Configuring a Dead-Letter Exchange

There are two ways to configure it. A queue argument is set when the queue is declared. A policy is set on the broker and applies to every queue whose name matches a pattern, and it can be changed later without redeclaring the queue, which is why policies are generally preferred for operational settings.

Java
// As queue arguments, declared from Spring AMQP
@Bean Queue orders() {
return QueueBuilder.durable("orders")
.quorum()
.deadLetterExchange("orders.dlx") // x-dead-letter-exchange
.deadLetterRoutingKey("orders.dead") // x-dead-letter-routing-key (optional)
.build();
}
@Bean DirectExchange ordersDlx() { return new DirectExchange("orders.dlx"); }
@Bean Queue ordersDlq() { return QueueBuilder.durable("orders.dlq").quorum().build(); }
@Bean Binding dlqBinding() { return BindingBuilder.bind(ordersDlq()).to(ordersDlx()).with("orders.dead"); }
# Or as a policy on the broker; the pattern here matches the queue named orders
rabbitmqctl set_policy orders-dlx "^orders$" '{"dead-letter-exchange":"orders.dlx"}' --apply-to queues

Notice that the dead-letter exchange must exist and have a binding to a queue. If it does not exist, or nothing is bound with a matching key, dead-lettered messages are simply dropped, with no error to the application. The routing key is optional: without x-dead-letter-routing-key, the message keeps its original routing keys.

3The Events That Dead-Letter a Message

RabbitMQ dead-letters a message in four situations. The first is a consumer rejecting it, with basic.reject or basic.nack, with requeue set to false. This is the path for messages a consumer decides it cannot process, such as a validation failure, and in Spring AMQP it is what happens with AmqpRejectAndDontRequeueException or default-requeue-rejected=false. The second is TTL expiry: a message that has been in the queue longer than its time to live, set per queue with x-message-ttl or per message with the expiration property, is dead-lettered instead of being delivered.

The third is the queue length limit. When a queue with x-max-length or x-max-length-bytes is full and its overflow behaviour is drop-head, the default, the oldest messages are pushed out and dead-lettered to make room. With overflow reject-publish, new messages are refused at publish time instead, so they never enter the queue and are not dead-lettered. The fourth applies to quorum queues only: each message's deliveries are counted, and once a message has been returned more times than the delivery limit, it is dead-lettered. A plain acknowledgement never dead-letters anything, and a reject with requeue true puts the message back instead.

Step throughWhich events dead-letter a message
  1. Message in queue ordershas a DLX configured
  2. Rejected with requeue=false?
    YesDead-letter: reason rejectedNoCheck TTL
  3. TTL expired?
    YesDead-letter: reason expiredNoCheck length limit
  4. Pushed out by max length (drop-head)?
    YesDead-letter: reason maxlenNoCheck delivery count
  5. Quorum queue over delivery limit?
    YesDead-letter: reason delivery_limitNoStays in the queue

5 steps in order. Play them, or step through them one at a time.

4Inside the x-death Header

When the broker dead-letters a message, it adds or updates a header called x-death. It is a list with one entry per combination of queue and reason, each recording the reason, the queue it was dead-lettered from, the exchange and routing keys it had, the time, and a count of how often that happened. Related headers such as x-first-death-reason and x-first-death-queue record the very first event.

YAML
x-death: [
{ reason: "rejected", queue: "orders", exchange: "orders",
routing-keys: ["order.created.eu"], count: 1, time: 2026-11-06T09:14:03Z }
]
x-first-death-reason: rejected
x-first-death-queue: orders
x-first-death-exchange: orders

So a person looking at orders.dlq can see at once where a message came from and why it ended up there. Retry designs also read x-death: when a message passes through a retry queue several times, the count in the matching entry tells the consumer how many attempts have been made. The exact set of fields has grown over RabbitMQ versions, so check your version's documentation before relying on a specific one.

5How the Dead-Lettered Message Is Routed

Once dead-lettered, the message is published to the dead-letter exchange, and from there everything works as normal routing. The exchange can be of any type: a direct exchange with one dead-letter queue per source queue keeps things simple, a topic exchange lets one DLX serve several queues, and a fanout sends dead letters to an alerting queue as well as a storage queue.

One detail matters for reliability. For classic queues, and by default for quorum queues, dead-lettering is at most once: if the dead-letter queue cannot accept the message, it is lost. Quorum queues offer an at-least-once dead-letter strategy, which needs overflow set to reject-publish on the source queue; it is worth enabling for important data.

6Follow-up questions

Can a dead-letter queue have its own dead-letter exchange?

Yes, it is an ordinary queue, so it can have a DLX, a TTL and a length limit. This is exactly how delayed retries are built: a retry queue with a TTL dead-letters expired messages back to the work exchange. RabbitMQ detects simple cycles where a message would loop through the same queue for the same reason without any rejection, and drops it in that case.

Should the consumer read from the dead-letter queue automatically?

Usually not for the main business logic, since the messages failed for a reason. A small tool or an operator inspects them, fixes the cause and replays them to the original exchange. Automated consumers of the DLQ are fine for alerting, counting and archiving.

7Conclusion

In this answer, we saw that dead-lettering is configured on a queue with x-dead-letter-exchange, and optionally x-dead-letter-routing-key, by argument or policy. A message is dead-lettered when it is rejected or nacked without requeue, when its TTL expires, when a drop-head length limit pushes it out, and on quorum queues when it exceeds the delivery limit. The broker records the reason, queue and count in the x-death header, and the dead-letter exchange routes the message onward like any exchange, so the exchange and its bindings must exist.

What to say in the interviewAbout 90 seconds aloud

Open with

Dead-lettering is configured on the queue. I give it a dead-letter exchange with the x-dead-letter-exchange argument, or better with a policy, because policies can change later without redeclaring the queue, and optionally a dead-letter routing key; otherwise the message keeps its original routing key.

Then, if they want more

When the queue gives up on a message, the broker republishes it to that exchange instead of discarding it. There are four triggers. A consumer rejects or nacks it with requeue false, which is what Spring AMQP does with AmqpRejectAndDontRequeueException. Its TTL expires, from a queue-level message TTL or a per-message expiration.

The queue hits its length limit with the default drop-head overflow, so the oldest messages are pushed out; with reject-publish the new message is refused instead and is not dead-lettered. And for quorum queues, the message exceeds the delivery limit.

When it dead-letters, the broker adds an x-death header with an entry per queue and reason, containing the reason such as rejected, expired or maxlen, the original queue, the exchange and routing keys, the time and a count, plus first-death headers. The dead-letter exchange is just a normal exchange, so it routes the message to a dead-letter queue through bindings.

If the exchange or the binding is missing, the message is dropped silently, so I always declare both.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
RabbitMQ documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does dead-lettering work in RabbitMQ, and which events cause a message to be...": https://scrivio-interview-library.netlify.app/spring-boot/rabbitmq-and-jms/14e01d65ac/