Search code examples
aws-sdkspring-cloudamazon-sqs

Spring Cloud AWS SQS Deletion Policy


We have a SQS listener, such as:

@MessageMapping("queueName")
void listen(String message) { ... }

This queue has redrive policy configured with an associated dead letter queue.

The problem is that the default Spring Cloud AWS implementation is deleting the message when polling it and wiring internally 3 retries for processing it, and failing afterwards.

I can see there is a SqsMessageDeletionPolicy enum with ALWAYS and ON_SUCCESS values, among others. I can't find in any documentation how can I change the QueueAttributes for that queue in order to change this behaviour.

Does anyone knows?


Solution

  • Seems like the solution is basically to use the SQS specific annotation instead of the generic one:

    @SqsListener(value = "queueName", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
    void listen(String message) { ... }