Closed arunkumarg26 closed 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...
@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");
}
}
@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
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.
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?