Dead Lettering

What is a dead letter exchange

Messages can be “dead-lettered” which means they can be re-published to an exchange (Dead Letter eXchange) when:

  1. A message is “negatively acknoledged” or NACK’ed
  1. The message expires on its TTL
  1. A message is dropped because the queue exceeded a length limit
  1. The message is returned more times to a quorum queue than the delivery limit

Messages are NOT dead lettered when an entire queue expires

How to configure

You specify the DLX via polices linked to a queue

You can also specify the these values via arguments in application code, and these will take presidence over polices.

Please consult the docs on how to do these. LINK

Routing Dead-Lettered Messages

Deal-letter loop

It is possible to loop rabbit messages, via passing them to the dead letter exchange and then back to the original exchange with the same routing key. If this happens rabbit will kill the message if no rejection was ever detected.

Safety

It is possible for messages to become lost.

Publisher Confirms is turned off by default. Thus using DLX is not always safe. Messages are removed from the original queue after the letter has arrived at the target DLX queue.

Dead-Lettered Effects on Messages

Dead-lettering a message will modify its headers:

Within the header a {Queue, Reason} pair specifies the history of the letter.

A x-death header holds an array of objects specifying information about previous dead lettering events. The most recent element in the array is the most recent dead-lettering event.

Table specifying all the fields
AMQP 1.0 keyAMQP 1.0 value typeAMQP 0.9.1 keyAMQP 0.9.1 value typeDescription
queuestringqueuelongstrThe name of the queue this message was dead lettered from.
reasonsymbolreasonlongstrWhy this message was dead lettered (described below).
countulongcountlongHow many times this message was dead lettered from this queue for this reason.
first-timetimestampWhen this message was dead lettered the first time from this queue for this reason.
last-timetimestampWhen this message was dead lettered the last time from this queue for this reason.
timetimestampWhen this message was dead lettered the first time from this queue for this reason.
exchangestringexchangelongstrThe exchange this message was published to before this message got dead lettered for the first time from this queue for this reason.
routing-keysarray of stringrouting-keysarray of longstrThe routing keys (including CC but excluding BCC) of this message before it got dead lettered for the first time from this queue for this reason.
ttluintAMQP 1.0 header's ttl (time to live in milliseconds) before this message got dead lettered for the first time from this queue for this reason.
original-expirationlongstrThe original expiration property of this message before it got dead lettered for the first time from this queue for this reason.