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

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

package software.amazon.lambda.powertools.sqs;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * {@code SqsLargeMessage} is used to signal that the annotated method
 * should be extended to handle large SQS messages which have been offloaded
 * to S3
 *
 * 

{@code SqsLargeMessage} automatically retrieves and deletes messages * which have been offloaded to S3 using the {@code amazon-sqs-java-extended-client-lib} * client library.

* *

This version of the {@code SqsLargeMessage} is compatible with version * 1.1.0+ of {@code amazon-sqs-java-extended-client-lib}.

* *
 * <dependency>
 *   <groupId>com.amazonaws</groupId>
 *   <artifactId>amazon-sqs-java-extended-client-lib</artifactId>
 *   <version>1.1.0</version>
 * </dependency>
 * 
* *

{@code SqsLargeMessage} should be used with the handleRequest method of a class * which implements {@code com.amazonaws.services.lambda.runtime.RequestHandler} with * {@code com.amazonaws.services.lambda.runtime.events.SQSEvent} as the first parameter.

* *
 * public class SqsMessageHandler implements RequestHandler {
 *
 *    {@literal @}Override
 *    {@literal @}SqsLargeMessage
 *     public String handleRequest(SQSEvent sqsEvent, Context context) {
 *
 *         // process messages
 *
 *         return "ok";
 *     }
 *
 *     ...
 * 
* *

Using the default S3 Client {@code AmazonS3 amazonS3 = AmazonS3ClientBuilder.defaultClient();} * each record received in the SQSEvent {@code SqsLargeMessage} will checked * to see if it's body contains a payload which has been offloaded to S3. If it * does then {@code getObject(bucket, key)} will be called and the payload * retrieved.

* *

Note: Retreiving payloads from S3 will increase the duration of the * Lambda function.

* *

If the request handler method returns then each payload will be deleted * from S3 using {@code deleteObject(bucket, key)}

* *

To disable deletion of payloads setting the following annotation parameter * {@code @SqsLargeMessage(deletePayloads=false)}

* */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface SqsLargeMessage { boolean deletePayloads() default true; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy