---
title: "Guaranteed Delivery using Dead Letter Queue · Appnovation"
url: "https://www.appnovation.com/insights/guaranteed-delivery-using-dead-letter-queue"
description: "How to implement guaranteed delivery in enterprise messaging using a dead letter queue, so messages are never lost even if systems crash."
---

Article

# Guaranteed Delivery using Dead Letter Queue

[![](https://cdn.sanity.io/images/ey850001/production/a3cb9ef4c624ceb5b24ff2fe2f9593eb13a35405-68x68.jpg?w=68&auto=format) lakshmi lakshmi Senior MuleSoft Developer](/people/lakshmi-lakshmi.md) Nov 14, 2017  
 3 min read 

![Guaranteed Delivery using Dead Letter Queue](https://cdn.sanity.io/images/ey850001/production/3e3752c1f1e90168e5130e1befa8efd691693e48-1400x400.png?w=1400&auto=format) 

When an [enterprise](/services.md) implements messaging, **Guaranteed Delivery** (Messages are persistent and are not lost even when the system crashes) becomes an imminent requirement.

When implementing messaging, ensuring Guaranteed Delivery means answers to the following:

*   Where does the message get sent when a condition is not met?
*   Can each individual message be re-delivered?
*   What happens to the message when an exception is thrown?

Before we answer these questions, let’s crack into “Dead Letter Queue”

What is “Dead Letter Queue”?

Dead Letter Queue is a service to store messages when:

*   The message that is sent to a queue doesn’t exist
*   Message length exceeds the limit set on Queue.
*   Message is rejected, by another queue or exchange.

Consider a simple example of accepting an http Inbound request, storing the message and then processing the [request.](/company/contact.md)

In the Publisher Flow (above diagram), Http Inbound connector delivers the message to the AMQP Outbound Connector, which connects to RabbitMQ.

\<amqp:outbound-endpoint

exchangeName="${rabbitmq.exchange.name}"

queueName="${rabbitmq.sendemail.message.queue}"

routingKey="${rabbitmq.sendemail.message.routingkey}"

exchangeType="direct"

exchangeDurable="true"

queueDurable="true"

responseTimeout="${rabbitmq.response.timeout}"

connector-ref="AMQP\_0\_9\_Connector"

doc:name="Publisher Flow">

\<reconnect frequency="${rabbitmq.reconnect.frequency}" count="${rabbitmq.reconnect.count}" />

\</amqp:outbound-endpoint>

The “reconnect” element ensures that the delivery of messages is **re-delivered** in case of connection errors to RabbitMQ.

The Subscriber Flow is configured with an AMQP Inbound Connector, listening to any messages received and then delivers the message to Application Flow – to perform business logic.

\<amqp:inbound-endpoint

exchangeName="${rabbitmq.exchange.name}"

queueName="${rabbitmq.sendemail.message.queue}"

routingKey="${rabbitmq.sendemail.message.routingkey}"

exchangeDurable="true"

exchangeType="direct"

queueDurable="true"

responseTimeout="${rabbitmq.response.timeout}"

connector-ref="AMQP\_0\_9\_Connector"

doc:name="Subscriber Flow">

\<reconnect frequency="${rabbitmq.reconnect.frequency}" count="${rabbitmq.reconnect.count}" />

*\<properties>*

*\<spring:entry key="amqp-queue.x-dead-letter-exchange" value="${rabbitmq.exchange.name}" />*

*\<spring:entry key="amqp-queue.x-dead-letter-routing-key" value="${rabbitmq.sendemail.message.dead.letter.routingkey}" />*

*\</properties>*

\</amqp:inbound-endpoint>

In the Subscriber flow, we have configured 2 additional properties to configure the dead letter queue. Messages will be sent to “Dead Letter Queue”, when the given **condition is not met**.

**Until, this point we have answered 2 major questions:**

**Where does the message get sent when a condition is not met?**

**How to configure re-delivery of messages?**

**Let’s look at what happens when there is an exception in the application flow (in the above diagram) and where does the message get sent.**

Typically, on successful processing of message, a positive “Acknowledgement” is sent to the queue, which then safely deletes the message from the queue.

\<amqp:acknowledge-message doc:name="AMQP-0-9 Acknowledge Message" />

But, when an exception occurs a “Reject” acknowledgement needs to be sent to the queue so that the message is rolled back into the queue for further use.

\<exception-strategy ref="global-choice-rollback-exception-strategy" doc:name="Reference Exception Strategy" />

A rollback exception strategy is configured as:

\<choice-exception-strategy name="global-choice-rollback-exception-strategy">

\<rollback-exception-strategy maxRedeliveryAttempts="${exception.strategy.rollback.attempts}">

\<choice>

\<when expression="#\[message.inboundProperties\['http.status'\] != null &amp;&amp; Integer.parseInt(message.inboundProperties\['http.status'\]) != 200\]">

\<flow-ref name="perform-api-error-event-logging" doc:name="perform-api-error-event-logging" />

\<set-property propertyName="Content-Type" value="application/json" doc:name="Property" />

\<set-payload value="#\[flowVars.payloadJson\]" doc:name="Set Response" />

\<json:object-to-json-transformer doc:name="Object to JSON" />

\</when>

\<otherwise>

\<logger message="No other exception handled" level="INFO" doc:name="Payload Logger" />

\</otherwise>

\</choice>

\<!-- re-queue message for re-tries -->

\<amqp:reject-message requeue="true" doc:name="AMQP-0-9 Reject Message" />

\<!-- reject message, this will deliver message to DLQ -->

\<on-redelivery-attempts-exceeded>

\<amqp:reject-message doc:name="AMQP-0-9

Reject Message" />

\</on-redelivery-attempts-exceeded>

\</rollback-exception-strategy>

\</choice-exception-strategy>

The rejected messages in a queue can be viewed in the queue browser (like RabbitMQ Admin Console). The rejected messages can then be processed manually after taking corrective actions or the recovery process can be automated.

In conclusion, we have looked at how to implement Guaranteed Delivery of messages and answered the core questions of Guaranteed Delivery.

[![](https://cdn.sanity.io/images/ey850001/production/a3cb9ef4c624ceb5b24ff2fe2f9593eb13a35405-68x68.jpg?w=68&auto=format) lakshmi lakshmi Senior MuleSoft Developer · Appnovation](/people/lakshmi-lakshmi.md) 

## Keep reading

[![Abstract graphic of white lines spiralling around a green-outlined triangle on a dark background](https://cdn.sanity.io/images/ey850001/production/e561f763d9608b75872d9b71d0674353c36a06fb-1201x630.png?w=640&auto=format)](/insights/2020-11-your-tech-stack-standing-way-your-success.md)

 Article · 4 min Nov 19, 2020 

### [Is Your Tech Stack Standing In The Way Of Your Success?](/insights/2020-11-your-tech-stack-standing-way-your-success.md)

Your business potential and technology needs (should) go hand in hand. You can plan business outcomes all you want, but if they’re not mapped strategically to the technology you need to actually make them happen, you’ll fail. Easy as that.

[Nathan Gervais](/people/nathan-gervais.md) Article 

[![Abstract graphic of white lines spiralling around a green-outlined triangle on a dark background](https://cdn.sanity.io/images/ey850001/production/e561f763d9608b75872d9b71d0674353c36a06fb-1201x630.png?w=640&auto=format)](/insights/2020-11-finding-your-way-build-your-migration-roadmap-drupal-9.md)

 Article · 4 min Nov 05, 2020 

### [Finding Your Way: Build Your Migration Roadmap to Drupal 9](/insights/2020-11-finding-your-way-build-your-migration-roadmap-drupal-9.md)

As we move toward 2021 and continue to reckon with COVID-19, digital-first companies need a plan to meet continuously shifting customer needs. Drupal 9 will help you do it.

[Nathan Gervais](/people/nathan-gervais.md) Article 

[![Abstract graphic of white lines spiralling around a green-outlined triangle on a dark background](https://cdn.sanity.io/images/ey850001/production/e561f763d9608b75872d9b71d0674353c36a06fb-1201x630.png?w=640&auto=format)](/insights/2020-10-move-drupal-9-and-exceed-cxpectations.md)

 Article · 5 min Oct 20, 2020 

### [Move to Drupal 9 and Exceed CXpectations](/insights/2020-10-move-drupal-9-and-exceed-cxpectations.md)

As we move toward 2021 and continue to reckon with COVID-19, digital-first companies need a plan to meet continuously shifting customer needs. Drupal 9 will help you do it.

[Nathan Gervais](/people/nathan-gervais.md) Article 

## Get the thinking,  
*before everyone else.*

One considered email a month. New essays, field notes from live engagements, and the occasional strong opinion. No noise.
