Skip to content

SQS Automatic Request Batching #5580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Sep 11, 2024
Merged

Conversation

joviegas
Copy link
Contributor

@joviegas joviegas commented Sep 9, 2024

Motivation and Context

Creating a Batch Manager

  1. Default Configuration via SqsAsyncClient:
    Users can easily obtain a SqsAsyncBatchManager with default configurations via SqsAsyncClient. This is the simplest approach, requiring minimal setup:
SqsAsyncClient asyncClient = SqsAsyncClient.create();
SqsAsyncBatchManager sqsAsyncBatchManager = asyncClient.batchManager();
  1. Custom Configuration via SqsAsyncBatchManager.Builder:
batchManager = SqsAsyncBatchManager.builder()
                                   .client(client)
                                   .scheduledExecutor(Executors.newScheduledThreadPool(5))
                                   .overrideConfiguration(b -> b
                                       .maxBatchSize(10)
                                       .sendRequestFrequency(Duration.ofMillis(200))
                                       .receiveMessageMinWaitDuration(Duration.ofSeconds(10))
                                       .receiveMessageVisibilityTimeout(Duration.ofSeconds(20))
                                       .receiveMessageAttributeNames(Collections.singletonList("*"))
                                       .receiveMessageSystemAttributeNames(Collections.singletonList(MessageSystemAttributeName.ALL)))
                                   .build();

Method Usage Scenarios

Sending Messages:

CompletableFuture<SendMessageResponse> futureOne = sqsAsyncBatchManager.sendMessage(r -> r.messageBody("One").queueUrl("queue"));
SendMessageResponse messageOne = futureOne.join();

Receiving Messages:

With default settings:

CompletableFuture<ReceiveMessageResponse> responseFuture = batchManager.receiveMessage(
    r -> r.queueUrl(defaultQueueUrl));

With custom timeout:

CompletableFuture<ReceiveMessageResponse> response = batchManager.receiveMessage(
    r -> r.queueUrl(defaultQueueUrl)
          .waitTimeSeconds(5)
          .visibilityTimeout(20));

With limited number of messages configured on Request:

CompletableFuture<ReceiveMessageResponse> response = batchManager.receiveMessage(
    r -> r.queueUrl(defaultQueueUrl)
          .maxNumberOfMessages(3));

Modifications

Please refer to the PR in the commit

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

joviegas and others added 23 commits June 28, 2024 09:46
…s for BatchManager (#5321)

* Codegenerate BatchManager API under AsyncClient and Add empty initial Batchmanager interfaces and Implementations

* Addressed review comments
…-sdk-java-v2 into feature/master/sqs-batch-manager
* Added Internal classes required for BatchManager Implementation

* Added Batch Send Implementation

* Handled review comments

* Handled review comments

* Handled review comments

* Made RequestBatchManager class a Abstract class

* Checkstyle issues

* Removed unused methods

* New lines removed

* Made public static to private state for sqsBatch functions

* Constants added

* Sonar cloud issues fixed

* commit to check why test on codebuild

* Increased Timeouts for get

* Added abstract methods

* Handled comments to remove Builders

* Handled comments to take care when batchmanager closed while pending requests

* Handled comments

* Checkstyle issue
* Add Recieve Buffer Queue And its related configuration

* Update ReceiveBatch  manager

* Recieve Batch Manager Implementation

* Receive Batch Manager Implemetation

* Handled review comments

* Checkstyle failure

* Flsky test case fixed

* Flaky test case fixed

* Hamdled review comments

* Handled comments

* Removed ReceiveMessageCompletableFuture

* SdkClosable implemented

* Added ReceiveMessageBatchManager class for completeness

* Checkstyle issues

* Null checks

* Handled comments from Zoe
* Initial changes

* Initial changes 2

* Byte Based batching for SendMessage API

* Byte Based batching for SendMessage API

* Handled comments
…5546)

* Add User Agent for Sqs Calls made using Automatic Batching Manager as hll/abm

* Review comments
* Update comments of PR 5488

* Update comments from  PR 5488
* Initial version

* Intermediate changes

* Update after internal poll

* ResponseCOnfiguration construction updated

* RequestOverride configuration check added to Bypass batch manager

* Handled review comments
…futures with empty messages (#5571)

* Fix issue where the Scheduled Timeout was incorrectly completing the futures with empty messages

* Handled review comments
@joviegas joviegas requested a review from a team as a code owner September 9, 2024 22:32
…n SQS

The new BatchManager allows for simple request batching using client-side buffering, improving cost efficiency and reducing the number of requests sent to Amazon SQS. The client-side buffering supports up to 10 requests per batch and is supported by the SqsAsyncClient. Batched requests, along with receive message polling, help to increase throughput.
@joviegas joviegas changed the title Automatic Batch Request SQS Automatic Request Batching Sep 10, 2024
joviegas and others added 2 commits September 10, 2024 12:16
…qsAsyncBatchManager (#5582)

* Add check for scheduledExecutor such that it not null when creating SqsAsyncBatchManager

* Update services/sqs/src/test/java/software/amazon/awssdk/services/sqs/batchmanager/SqsAsyncBatchManagerBuilderTest.java

Co-authored-by: David Ho <[email protected]>

* Update services/sqs/src/test/java/software/amazon/awssdk/services/sqs/batchmanager/SqsAsyncBatchManagerBuilderTest.java

Co-authored-by: David Ho <[email protected]>

* Update services/sqs/src/test/java/software/amazon/awssdk/services/sqs/batchmanager/SqsAsyncBatchManagerBuilderTest.java

Co-authored-by: David Ho <[email protected]>

---------

Co-authored-by: David Ho <[email protected]>
@joviegas joviegas enabled auto-merge September 11, 2024 21:21
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@joviegas joviegas added this pull request to the merge queue Sep 11, 2024
Merged via the queue into master with commit 40bdde8 Sep 11, 2024
17 of 18 checks passed
@jhchee
Copy link

jhchee commented Sep 22, 2024

Hi @joviegas thanks for the great work! I believe there's a need to update the documentation at here as well.

@joviegas
Copy link
Contributor Author

joviegas commented Oct 18, 2024

Hi @joviegas thanks for the great work! I believe there's a need to update the documentation at [here] (https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-client-side-buffering-request-batching.html#using-buffered-async-client) as well.

Hi @jhchee
Thanks for reaching out
I am working on releasing a new blog post , might take some time due to other priorities but will try my best .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants