AWS

How to Process Messages in Dead Letter Queue

Amazon SQS easily lets the users store and transfer messages between software components.

Users create queues in the amazon SQS and send and receive messages in those queues. The dead letter queue contains messages which cannot be processed.

Messages stored in the dead letter queue can be processed to the main queue by manually resending the message. One way to do so is to go to the dead letter queue and get the contents of the messages in the dead letter queue and then send the message contents to the main queue. But instead of manual processing, we will process messages through poll messages.

This article will cover each step, from creating the queues to shifting the messages within those queues.

Creating Queues

First, we need to create the queues. Go to the SQS (Simple Queue Service) to create the queues.

On the Amazon SQS page or interface click on the Create queue option in the Get started area to start the process of creating a queue.

Select the First in, first out method (FIFO).

Name the Main queue with the .fifo extension.

Select Create queue and proceed.

Now, repeat the same process for creating a Dead Letter queue.

In this way, the main queue MainQueue.fifo and the dead letter queue DeadLetterQueue.fifo have been created.

Both queues have been created successfully.

Creating a Message

Now select the main queue and click on edit. Scroll down to the Dead-letter-queue option.

Enable the queue to receive undeliverable messages and choose the arn of the other queue (dead-letter-queue).

Set the maximum received to the number according to the time’s message can be shifted between the main and the dead letter queue.

Now, select the main queue again and click on Send and receive messages option to send a message in the queue.

A page will appear that lets the users properly create a new message to add to the queue. Type any message along with the message ID and message duplication ID.

Click on the Send message button.

Now, we have 2 queues and 1 message in the main queue.

Select the main queue. Then, choose the Send and receive messages option.

Scroll down to the Recieve messages area and click on the Poll for messages option.

When the process starts, the message will shift to the Messages in flight columns, and when it completes, it will shift again to the column of Messages available. Repeating this step will shift the message into the Dead letter queue.

We assume our message is in the dead letter queue, and we must make it processable.

Processing Messages in Dead Letter Queue

Now that the message is in the dead letter queue, we want to process or shift it to the main queue. We can repeat the same process. Select the dead letter queue and then click on the edit button.

Scroll down to the dead-letter-queue option and enable the undeliverable messages queue and then add the arn of the main queue.

Click on the Send and receive button.

Scroll down to the bottom to the Receive messages area. Select the Poll for messages option.

While the polling is in progress,Β  the number of messages will appear in the Messages in flight column and, after some time, will again appear in the Messages available on the dead letter queue.

Because the maximum received is set to 1, polling again will not let the message remain in the same queue; rather, it will shift the message from the dead letter queue to the main queue.

The message is then processed and displayed in the main queue.

This was the detailed procedure for creating and processing the queues.

Conclusion

Messages present in the dead letter queue are those which cannot be processed or consumed. They can be made processable by shifting to the other queues by polling the messages from one queue to the other. Adding arn of the other queue in the dead letter queue and setting the maximum receives value to 1 polled the message in the dead letter queue to the main queue.

About the author

Abdul Mannan

I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.