Changes in automatic Amazon SQS request batching from version 1 to version 2
This topic details the changes in automatic request batching for Amazon SQS between version 1 and version 2 of the Amazon SDK for Java.
High-level changes
The Amazon SDK for Java 1.x performs client-side buffering using a separate AmazonSQSBufferedAsyncClient class that requires explicit
initialization for request batching.
The Amazon SDK for Java 2.x simplifies and enhances buffering functionality with the SqsAsyncBatchManager. The implementation of this interface provides
automatic request batching capabilities directly integrated with the standard SqsAsyncClient. To learn about v2's
SqsAsyncBatchManager, see the Use automatic request batching for Amazon SQS with the
Amazon SDK for Java 2.x topic in this
guide.
| Change | v1 | v2 |
|---|---|---|
|
Maven dependencies |
|
|
| Package names | com.amazonaws.services.sqs.buffered |
software.amazon.awssdk.services.sqs.batchmanager |
| Class names | SqsAsyncBatchManager |
1
Latest
version
Using automatic SQS request batching
| Change | v1 | v2 |
|---|---|---|
| Create a batch manager |
|
|
| Create a batch manager with custom configuration |
|
|
| Send messages |
|
|
| Delete messages |
|
|
| Change visibility of messages |
|
|
| Receive messages |
|
|
Asynchronous return type differences
| Change | v1 | v2 |
|---|---|---|
| Return type | Future<ResultType> |
CompletableFuture<ResponseType> |
| Callback mechanism | Requires an AsyncHandler with separate onSuccess
and onError methods |
Uses CompletableFuture APIs provided by the JDK, such as
whenComplete(), thenCompose(),
thenApply() |
| Exception handling | Uses AsyncHandler#onError() method |
Uses CompletableFuture APIs provided by the JDK, such as
exceptionally(), handle(), or
whenComplete() |
| Cancellation | Basic support through Future.cancel() |
Cancelling a parent CompletableFuture automatically cancels
all dependent futures in the chain |
Asynchronous completion handling differences
| Change | v1 | v2 |
|---|---|---|
| Response handler implementation |
|
|
Key configuration parameters
| Parameter | v1 | v2 |
|---|---|---|
| Maximum batch size | maxBatchSize (default 10 requests per batch) |
maxBatchSize (default 10 requests per batch) |
| Batch wait time | maxBatchOpenMs (default 200 ms) |
sendRequestFrequency (default 200 ms) |
| Visibility timeout | visibilityTimeoutSeconds (-1 for queue default) |
receiveMessageVisibilityTimeout (queue default) |
| Minimum wait time | longPollWaitTimeoutSeconds (20s when longPoll is
true) |
receiveMessageMinWaitDuration (default 50 ms) |
| Message attributes | Set using ReceiveMessageRequest |
receiveMessageAttributeNames (none by default) |
| System attributes | Set using ReceiveMessageRequest |
receiveMessageSystemAttributeNames (none by default) |
| Long polling | longPoll (default is true) |
Not supported to avoid open connections waiting until the server sends the messages |
| Maximum wait time for long polling | longPollWaitTimeoutSeconds (default 20s) |
Not supported to avoid open connections waiting until the server sends the messages |
| Maximum number of prefetched receive batches stored client-side | maxDoneReceiveBatches (10 batches) |
Not supported because it is handled internally |
| Maximum number of active outbound batches processed simultaneously | maxInflightOutboundBatches (default 5 batches) |
Not supported because it is handled internally |
| Maximum number of active receive batches processed simultaneously | maxInflightReceiveBatches (default 10 batches) |
Not supported because it is handled internally |