Skip to content

Conversation

@phipag
Copy link
Contributor

@phipag phipag commented Oct 31, 2025

Summary

This PR introduces an AspectJ-free function API for the Large Messages utility. Instead of annotation a method with @LargeMessage the following code can be written (example together with batch processing):

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) {
        LargeMessages.processLargeMessage(sqsMessage, this::handleProcessedMessage);
    }

    private void handleProcessedMessage(SQSEvent.SQSMessage processedMessage) {
        // processedMessage.getBody() will contain the content of the S3 Object
        // do something with the message
    }
}

This API is thread-safe.

For multi-parameter methods, the following simple pattern can be used:

public void handleRequest(SQSEvent event, Context context) {
    event.getRecords().forEach(message ->
        LargeMessages.processLargeMessage(message, processedMsg -> processMessage(processedMsg, context))
    );
}

It is important to note that the utility modifies the SQSMessage in-place to avoid duplicating large blobs in-memory.

Changes

To the reviewers: Ignore PMD findings regarding "Throwable" or "unused parameters". This is expected.

  • Throwable needs to be catched for AspectJ compatibility
  • Unused parameters is a unit test where the goal is to test this

Issue number: #2212


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 3, 2025

@phipag phipag moved this to Pending review in Powertools for AWS Lambda (Java) Nov 3, 2025
@phipag phipag marked this pull request as ready for review November 3, 2025 09:45
@phipag phipag linked an issue Nov 3, 2025 that may be closed by this pull request
2 tasks
@phipag phipag merged commit 71c632b into main Nov 3, 2025
21 checks passed
@phipag phipag deleted the phipag/issue2212 branch November 3, 2025 10:42
@github-project-automation github-project-automation bot moved this from Pending review to Coming soon in Powertools for AWS Lambda (Java) Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Coming soon

Development

Successfully merging this pull request may close these issues.

Feature request: Support functional interface for Large Messages utility

2 participants