1

I've configured a DLQ in AWS following this article: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-configure-dead-letter-queue.html

This is the consumer I have in a sprint boot application:

@SqsListener(value = "${cloud.aws.endpoint.queue-name}", deletionPolicy = SqsMessageDeletionPolicy.DEFAULT)
private void getMessage(final Event event) {
    // process event
}

However, when there is an exception during the event processing, say a NPE, an exception calling an external REST API etc, the messages that failed to be processed are not flowing into the dead letter queue.

Am I missing anything?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Carlos Gonzalez
  • 607
  • 1
  • 5
  • 13

1 Answers1

0

It's difficult to help with the few info you provide but check the following:

Perhaps your queue is not properly setup

Dead letter queues redirection are not related to the consumer setup but to the way that the queues have been configured at creation in aws. So use the aws cli get-queue-attributes command https://docs.aws.amazon.com/cli/latest/reference/sqs/get-queue-attributes.html to check if your source queue has the proper RedrivePolicy. The output should display something like this example. Also controls that the maxReceiveCount is setup properly in your source queue. From the doc:

maxReceiveCount – The number of times a message is delivered
to the source queue before being moved to the dead-letter queue.
When the ReceiveCount for a message exceeds the maxReceiveCount for a queue,
Amazon SQS moves the message to the dead-letter-queue.

If the dead letter queue has not been configured properly follow the aws create-queue https://docs.aws.amazon.com/cli/latest/reference/sqs/create-queue.html cli example to setup a dead letter queue to the source queue.

Try to send a message to the queue outside of spring using cli only with send-message https://docs.aws.amazon.com/cli/latest/reference/sqs/send-message.html and ensure that the dead letter queue is properly popolated.

Perhaps SqsListener is not pointing to the correct source queue

Messages may not be reaching the correct source queue that has a dead-letter queue attached. cloud.aws.endpoint.queue-name should be the path to find the queue name in your application properties application.yml like you just defined it:

cloud:
 aws:
  endpoint:
   queue-name: "my-queue-name"
Geoffrey
  • 69
  • 1
  • 2
  • 5