All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.lambda.powertools.sqs.SQSBatchProcessingException Maven / Gradle / Ivy

package software.amazon.lambda.powertools.sqs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.amazonaws.services.lambda.runtime.events.SQSEvent;

import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
import static java.util.Collections.*;
import static java.util.stream.Collectors.joining;

/**
 * 

* When one or more {@link SQSMessage} fails and if any exception is thrown from {@link SqsMessageHandler#process(SQSMessage)} * during processing of a messages, this exception is with all the details of successful and failed messages. *

* *

* This exception can be thrown form: *

    *
  • {@link SqsBatch}
  • *
  • {@link SqsUtils#batchProcessor(SQSEvent, Class)}
  • *
  • {@link SqsUtils#batchProcessor(SQSEvent, boolean, Class)}
  • *
  • {@link SqsUtils#batchProcessor(SQSEvent, SqsMessageHandler)}
  • *
  • {@link SqsUtils#batchProcessor(SQSEvent, boolean, SqsMessageHandler)}
  • *
*

*/ public class SQSBatchProcessingException extends RuntimeException { private final List exceptions; private final List failures; private final List returnValues; public SQSBatchProcessingException(final List exceptions, final List failures, final List successReturns) { super(exceptions.stream() .map(Throwable::toString) .collect(joining("\n"))); this.exceptions = new ArrayList<>(exceptions); this.failures = new ArrayList<>(failures); this.returnValues = new ArrayList<>(successReturns); } /** * Details for exceptions that occurred while processing messages in {@link SqsMessageHandler#process(SQSMessage)} * @return List of exceptions that occurred while processing messages */ public List getExceptions() { return unmodifiableList(exceptions); } /** * List of returns from {@link SqsMessageHandler#process(SQSMessage)} that were successfully processed. * @return List of returns from successfully processed messages */ public List successMessageReturnValues() { return unmodifiableList(returnValues); } /** * Details of {@link SQSMessage} that failed in {@link SqsMessageHandler#process(SQSMessage)} * @return List of failed messages */ public List getFailures() { return unmodifiableList(failures); } @Override public void printStackTrace() { for (Exception exception : exceptions) { exception.printStackTrace(); } } }