Skip to content

Commit c0cd20b

Browse files
committed
Rejig
1 parent 0f78133 commit c0cd20b

File tree

1 file changed

+4
-9
lines changed
  • powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs

1 file changed

+4
-9
lines changed

powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/SqsUtils.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,6 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
495495
client = SqsClient.create();
496496
}
497497

498-
// If we are working on a FIFO queue, when any message fails we should stop processing and return the
499-
// rest of the batch as failed too. We use this variable to track when that has happened.
500-
// https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting
501-
502498
BatchContext batchContext = new BatchContext(client);
503499
Queue<SQSMessage> messagesToProcess = new LinkedList<>(event.getRecords());
504500
while (!messagesToProcess.isEmpty()) {
@@ -514,7 +510,8 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
514510

515511
// If we are trying to process a message that has a messageGroupId, we are on a FIFO queue. A failure
516512
// now stops us from processing the rest of the batch; we break out of the loop leaving unprocessed
517-
// messages in the queu
513+
// messages in the queue
514+
// https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting
518515
String messageGroupId = message.getAttributes() != null ?
519516
message.getAttributes().get(MESSAGE_GROUP_ID) : null;
520517
if (messageGroupId != null) {
@@ -528,15 +525,13 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
528525

529526
// If we have a FIFO batch failure, unprocessed messages will remain on the queue
530527
// past the failed message. We have to add these to the errors
531-
while (!messagesToProcess.isEmpty()) {
532-
SQSMessage message = messagesToProcess.remove();
528+
messagesToProcess.forEach(message -> {
533529
LOG.info("Skipping message {} as another message with a message group failed in this batch",
534530
message.getMessageId());
535531
batchContext.addFailure(message, new SkippedMessageDueToFailedBatchException());
536-
}
532+
});
537533

538534
batchContext.processSuccessAndHandleFailed(handlerReturn, suppressException, deleteNonRetryableMessageFromQueue, nonRetryableExceptions);
539-
540535
return handlerReturn;
541536
}
542537

0 commit comments

Comments
 (0)