Getting SQS dead letter queue to work with Spring Boot and JMS

Question:

I’ve been working on a small Spring Boot application that receives messages from Amazon SQS. However I foresee that processing these messages may fail, so that’s why I thought adding a dead letter queue would be a good idea.

There is a problem though: when the processing fails (which I force by throwing an Exception for some of the messages) it is not reattempted later on and it’s not moved to the dead letter queue. I am struggling to find the issue, since there doesn’t seem to much info on it.

However if I look at Amazon’s documentation, they seem to be able to do it, but without using the Spring Boot annotations. Is there any way I can make the code below work transactional without writing too much of the JMS code myself?

This is the current configuration that I am using.

And finally the receiving end:

Answer:

Spring Cloud AWS

You can greatly simplify your configuration by leveraging Spring Cloud AWS.

MessageHandler

The example shown above is all you need to receive messages. This assumes you’ve created an sqs queue with an associated dead letter queue. If you’re messages aren’t acknowledged, then they will be retried again until they reach the maximum # of receives. Then it will be forwarded to the dead letter queue.

Leave a Reply