generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Labels
Description
Use case
The Large Messages utility currently only offers a benefit to developers when used with the AspectJ @LargeMessage annotation. The purpose of this feature request is to add a functional interface to initialize the Large message utility independent of AspectJ. For example, by wrapping it in a higher order function.
Solution/User Experience
The proposed design is below. We need ensure thread-safety here as well especially because this can be used with the parallel batch processor!
Usage with AspectJ
public class SqsBatchHandler implements RequestHandler<SQSEvent, SQSBatchResponse> {
private final BatchMessageHandler<SQSEvent, SQSBatchResponse> handler;
public SqsBatchHandler() {
handler = new BatchMessageHandlerBuilder()
.withSqsBatchHandler()
.buildWithRawMessageHandler(this::processMessage);
}
@Override
public SQSBatchResponse handleRequest(SQSEvent sqsEvent, Context context) {
return handler.processBatch(sqsEvent, context);
}
@LargeMessage
private void processMessage(SQSEvent.SQSMessage sqsMessage) {
// do something with the message
}
}
Usage without AspectJ
public class SqsBatchHandler implements RequestHandler<SQSEvent, SQSBatchResponse> {
private final BatchMessageHandler<SQSEvent, SQSBatchResponse> handler;
public SqsBatchHandler() {
handler = new BatchMessageHandlerBuilder()
.withSqsBatchHandler()
.buildWithRawMessageHandler(this::processMessage);
}
@Override
public SQSBatchResponse handleRequest(SQSEvent sqsEvent, Context context) {
return handler.processBatch(sqsEvent, context);
}
private void processMessage(SQSEvent.SQSMessage sqsMessage) {
PowertoolsLargeMessages.processLargeMessage(sqsMessage, this::handleProcessedMessage);
}
private void handleProcessedMessage(SQSEvent.SQSMessage processedMessage) {
// do something with the message - S3 content already retrieved
}
}
We can pass directly a Lambda function to the processRawMessage
method as well:
public class SqsBatchHandler implements RequestHandler<SQSEvent, SQSBatchResponse> {
private final BatchMessageHandler<SQSEvent, SQSBatchResponse> handler;
public SqsBatchHandler() {
handler = new BatchMessageHandlerBuilder()
.withSqsBatchHandler()
.buildWithRawMessageHandler(message ->
PowertoolsLargeMessages.processLargeMessage(message, this::handleProcessedMessage)
);
}
@Override
public SQSBatchResponse handleRequest(SQSEvent sqsEvent, Context context) {
return handler.processBatch(sqsEvent, context);
}
private void handleProcessedMessage(SQSEvent.SQSMessage processedMessage) {
// do something with the message - S3 content already retrieved
}
}
Alternative solutions
N/A
Acknowledgment
- This feature request meets Powertools for AWS Lambda (Java) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, TypeScript, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Backlog