Skip to content

Java V2: migrate v1 sqs example that compares single messaging to batch messaging #7509

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion .doc_gen/metadata/sqs_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,37 @@ sqs_Scenario_SendReceiveBatch:
- description: Use the wrapper functions to send and receive messages in batches.
snippet_tags:
- python.example_code.sqs.Scenario_SendReceiveBatch
Java:
versions:
- sdk_version: 2
github: javav2/example_code/sqs
sdkguide:
excerpts:
- description: >-
You can handle batch message operations with Amazon SQS using two different approaches
with the &JavaV2long;:</para>
<para><emphasis role="strong">SendRecvBatch.java</emphasis> uses explicit batch operations.
You manually create message batches and call <code>sendMessageBatch()</code> and
<code>deleteMessageBatch()</code> directly. You also handle batch responses, including any
failed messages. This approach gives you full control over batch sizing and error handling.
However, it requires more code to manage the batching logic.</para>
<para><emphasis role="strong">SimpleProducerConsumer.java</emphasis> uses the high-level
<code>SqsAsyncBatchManager</code> library for automatic request batching. You make
individual <code>sendMessage()</code> and <code>deleteMessage()</code> calls with the same
method signatures as the standard client. The SDK automatically buffers these calls and
sends them as batch operations. This approach requires minimal code changes while providing
batching performance benefits.</para>
<para>Use explicit batching when you need fine-grained control over batch composition and
error handling. Use automatic batching when you want to optimize performance with minimal
code changes.</para>
<para><emphasis role="strong">SendRecvBatch.java</emphasis> - Uses explicit batch operations with messages.
snippet_tags:
- sqs.java2.sendRecvBatch.main
- description: <emphasis role="strong">SimpleProducerConsumer.java</emphasis> - Uses automatic batching of messages.
snippet_tags:
- sqs.java2.batch_demo.main
services:
sqs: {CreateQueue, DeleteQueue, SendMessageBatch, ReceiveMessage, DeleteMessageBatch}
sqs: {CreateQueue, DeleteQueue, SendMessageBatch, SendMessage, ReceiveMessage, DeleteMessageBatch, DeleteMessage}
sqs_GetQueueAttributes:
languages:
.NET:
Expand Down
17 changes: 17 additions & 0 deletions javav2/example_code/sqs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ functions within the same service.
- [Manage large messages using S3](src/main/java/com/example/sqs/SqsExtendedClientExample.java)
- [Process S3 event notifications](../s3/src/main/java/com/example/s3/ProcessS3EventNotification.java)
- [Publish messages to queues](../../usecases/topics_and_queues/src/main/java/com/example/sns/SNSWorkflow.java)
- [Send and receive batches of messages](src/main/java/com/example/sqs/SendRecvBatch.java)
- [Use the Amazon SQS Java Messaging Library to work with the JMS interface](../sqs-jms/src/main/java/com/example/sqs/jms/stdqueue/TextMessageSender.java)
- [Work with queue tags](src/main/java/com/example/sqs/TagExamples.java)

Expand Down Expand Up @@ -130,6 +131,22 @@ This example shows you how to do the following:
<!--custom.scenarios.sqs_Scenario_TopicsAndQueues.start-->
<!--custom.scenarios.sqs_Scenario_TopicsAndQueues.end-->

#### Send and receive batches of messages

This example shows you how to do the following:

- Create an Amazon SQS queue.
- Send batches of messages to the queue.
- Receive batches of messages from the queue.
- Delete batches of messages from the queue.

<!--custom.scenario_prereqs.sqs_Scenario_SendReceiveBatch.start-->
<!--custom.scenario_prereqs.sqs_Scenario_SendReceiveBatch.end-->


<!--custom.scenarios.sqs_Scenario_SendReceiveBatch.start-->
<!--custom.scenarios.sqs_Scenario_SendReceiveBatch.end-->

#### Use the Amazon SQS Java Messaging Library to work with the JMS interface

This example shows you how to use the Amazon SQS Java Messaging Library to work with the JMS interface.
Expand Down
Loading
Loading