spring-attic / spring-cloud-aws

All development has moved to https://github.com/awspring/spring-cloud-aws Integration for Amazon Web Services APIs with Spring
https://awspring.io/
Apache License 2.0
590 stars 373 forks source link

SqsMessageDeletionPolicy.ON_SUCCESS deletes a message even if the listener method throws an exception #506

Closed arunkumarg26 closed 4 years ago

arunkumarg26 commented 4 years ago

Question

According to the SqsMessageDeletionPolicy.java documentation, the ON_SUCCESS does the following: "Deletes message when successfully executed by the listener method. If an exception is thrown by the listener method, the message will not be deleted". However, when the listener method throws an exception, the message is removed from the SQS queue

Is it mandatory to configure the re-drive policy to get the messages that are deleted while the exception is thrown?

arunkumarg26 commented 4 years ago

When I listener method throws an exception, the messages are deleted from the SQS queue. Is it mandatory to configure the re-drive policy? plmk...

dafuemu commented 4 years ago

@arunkumar-ebsco I don't know exactly how you implemented the reading from the SQS queue, but I noticed the following, when I add the @Async feature to the listener I throw an Exception and the message is deleted:

@EnableSqs
@EnableAsync
public class SQSDataListener {

    @Async
    @SqsListener(value = "${service.sqs.queueSubUrl}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
    public void process(final String payload, @Headers final Map<String, String> headers) throws Exception {
            throw new Exception("Delete message");

    }
}

but when I disable this feature the message is not deleted as expected:

@EnableSqs
//@EnableAsync
public class SQSDataListener {

    //@Async
    @SqsListener(value = "${service.sqs.queueSubUrl}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
    public void process(final String payload, @Headers final Map<String, String> headers) throws Exception {
            throw new Exception("Delete message");

    }
}
suniltamoli commented 4 years ago

@Async provide control to worker thread and return to main thread pool that is why it delete the message from sqs while worker thread throw exception during code processing . when you do not use @Async then main thread complete the work and the delete the message as per define deletion policy deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS

maciejwalkowiak commented 4 years ago

As @suniltamoli described. I could not reproduce your issue, if you're still facing it please create example that reproduces the problem and I am happy to take a look.