@@ -495,10 +495,6 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
495
495
client = SqsClient .create ();
496
496
}
497
497
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
-
502
498
BatchContext batchContext = new BatchContext (client );
503
499
Queue <SQSMessage > messagesToProcess = new LinkedList <>(event .getRecords ());
504
500
while (!messagesToProcess .isEmpty ()) {
@@ -514,7 +510,8 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
514
510
515
511
// If we are trying to process a message that has a messageGroupId, we are on a FIFO queue. A failure
516
512
// 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
518
515
String messageGroupId = message .getAttributes () != null ?
519
516
message .getAttributes ().get (MESSAGE_GROUP_ID ) : null ;
520
517
if (messageGroupId != null ) {
@@ -528,15 +525,13 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
528
525
529
526
// If we have a FIFO batch failure, unprocessed messages will remain on the queue
530
527
// 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 -> {
533
529
LOG .info ("Skipping message {} as another message with a message group failed in this batch" ,
534
530
message .getMessageId ());
535
531
batchContext .addFailure (message , new SkippedMessageDueToFailedBatchException ());
536
- }
532
+ });
537
533
538
534
batchContext .processSuccessAndHandleFailed (handlerReturn , suppressException , deleteNonRetryableMessageFromQueue , nonRetryableExceptions );
539
-
540
535
return handlerReturn ;
541
536
}
542
537
0 commit comments