Fix/enhance sqs partial acknowledgement handling#1562
Fix/enhance sqs partial acknowledgement handling#1562co2plant wants to merge 7 commits intoawspring:mainfrom
Conversation
- Changed null to DeleteMessageBatchResponse
tomazfernandes
left a comment
There was a problem hiding this comment.
Thanks for the PR @co2plant, on a first glance looks good.
Notice that SqsAcknowledgementException has a constructor that accepts separate lists for successfully acknowledged messages and failed acknowledgement messages - it would be useful to populate the lists according to AWS response.
Thanks.
DeleteMessageBatch response - Correlate items using message IDs for accurate mapping - Pass different lists to the SqsAcknowledgementException constructor to handle partial failures
- Extract partial error handling logic from the deleteMessages method - Improved code readability and maintainability - placed the calling method at the top and the helper method at the bottom
|
Thanks for the review @tomazfernandes! I was wondering how to separate the failures from the full failures, and your review was very helpful. I updated the code to map item IDs to message IDs based on the AWS responses and populate the success/failure lists.
|
tomazfernandes
left a comment
There was a problem hiding this comment.
Hey @co2plant, looking good.
Left a few suggestions. Also, can you please add a section in the docs explaining how partial Acknowledgement failures are handled?
We could also add to the docs that the resulting SqsAcknowledgementException will be available in AcknowledgementResultCallback, so failed exceptions can be inspected and e.g. retry acknowledging them.
| .thenRun(() -> {}), | ||
| t -> CompletableFutures.failedFuture(createAcknowledgementException(messagesToAck, t))) | ||
| .thenCompose(response -> { | ||
| if (!response.failed().isEmpty()) { |
There was a problem hiding this comment.
Nit: can we move this logic to a separate method?
| given(queueAttributes.getQueueName()).willReturn(queueName); | ||
| given(queueAttributes.getQueueUrl()).willReturn(queueUrl); | ||
|
|
||
| BatchResultErrorEntry failedEntry = BatchResultErrorEntry.builder().id("test-id").code("ReceiptHandleIsInvalid") |
There was a problem hiding this comment.
Shouldn't this id match the one in the message?
| executor.setQueueAttributes(queueAttributes); | ||
|
|
||
| assertThatThrownBy(() -> executor.execute(messages).join()).isInstanceOf(CompletionException.class) | ||
| .hasCauseInstanceOf(SqsAcknowledgementException.class); |
There was a problem hiding this comment.
Let's add assertions to verify getFailedAcknowledgementMessages() contains the message. We could also add successful messages to verify the exception is being create properly.

📢 Type of change
📜 Description
#1497
I first added logging for partial failures.
I checked the directory and found "SqsTemplate.deleteMessages," so I tried to refactor it to match the style as closely as possible.
💡 Motivation and Context
💚 How did you test it?
In the test code (sqs/listener/acknowledgement/SqsAcknowledgementExecutorTests.java), I changed null to DeleteMessageBatchResponse and added code for partial failures.
📝 Checklist
🔮 Next steps