Skip to content

Commit 6cf888b

Browse files
authored
Java V2: migrate v1 sqs example that compares single messaging to batch messaging (#7509)
* Add migrated v1 SQS example that demonstrates batching Addresses: https://issues.amazon.com/issues/V1651096945
1 parent adee179 commit 6cf888b

File tree

6 files changed

+1379
-1
lines changed

6 files changed

+1379
-1
lines changed

.doc_gen/metadata/sqs_metadata.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,37 @@ sqs_Scenario_SendReceiveBatch:
867867
- description: Use the wrapper functions to send and receive messages in batches.
868868
snippet_tags:
869869
- python.example_code.sqs.Scenario_SendReceiveBatch
870+
Java:
871+
versions:
872+
- sdk_version: 2
873+
github: javav2/example_code/sqs
874+
sdkguide:
875+
excerpts:
876+
- description: >-
877+
You can handle batch message operations with Amazon SQS using two different approaches
878+
with the &JavaV2long;:</para>
879+
<para><emphasis role="strong">SendRecvBatch.java</emphasis> uses explicit batch operations.
880+
You manually create message batches and call <code>sendMessageBatch()</code> and
881+
<code>deleteMessageBatch()</code> directly. You also handle batch responses, including any
882+
failed messages. This approach gives you full control over batch sizing and error handling.
883+
However, it requires more code to manage the batching logic.</para>
884+
<para><emphasis role="strong">SimpleProducerConsumer.java</emphasis> uses the high-level
885+
<code>SqsAsyncBatchManager</code> library for automatic request batching. You make
886+
individual <code>sendMessage()</code> and <code>deleteMessage()</code> calls with the same
887+
method signatures as the standard client. The SDK automatically buffers these calls and
888+
sends them as batch operations. This approach requires minimal code changes while providing
889+
batching performance benefits.</para>
890+
<para>Use explicit batching when you need fine-grained control over batch composition and
891+
error handling. Use automatic batching when you want to optimize performance with minimal
892+
code changes.</para>
893+
<para>SendRecvBatch.java - Uses explicit batch operations with messages.
894+
snippet_tags:
895+
- sqs.java2.sendRecvBatch.main
896+
- description: SimpleProducerConsumer.java - Uses automatic batching of messages.
897+
snippet_tags:
898+
- sqs.java2.batch_demo.main
870899
services:
871-
sqs: {CreateQueue, DeleteQueue, SendMessageBatch, ReceiveMessage, DeleteMessageBatch}
900+
sqs: {CreateQueue, DeleteQueue, SendMessageBatch, SendMessage, ReceiveMessage, DeleteMessageBatch, DeleteMessage}
872901
sqs_GetQueueAttributes:
873902
languages:
874903
.NET:

javav2/example_code/sqs/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ functions within the same service.
5757
- [Manage large messages using S3](src/main/java/com/example/sqs/SqsExtendedClientExample.java)
5858
- [Process S3 event notifications](../s3/src/main/java/com/example/s3/ProcessS3EventNotification.java)
5959
- [Publish messages to queues](../../usecases/topics_and_queues/src/main/java/com/example/sns/SNSWorkflow.java)
60+
- [Send and receive batches of messages](src/main/java/com/example/sqs/SendRecvBatch.java)
6061
- [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)
6162
- [Work with queue tags](src/main/java/com/example/sqs/TagExamples.java)
6263

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

134+
#### Send and receive batches of messages
135+
136+
This example shows you how to do the following:
137+
138+
- Create an Amazon SQS queue.
139+
- Send batches of messages to the queue.
140+
- Receive batches of messages from the queue.
141+
- Delete batches of messages from the queue.
142+
143+
<!--custom.scenario_prereqs.sqs_Scenario_SendReceiveBatch.start-->
144+
<!--custom.scenario_prereqs.sqs_Scenario_SendReceiveBatch.end-->
145+
146+
147+
<!--custom.scenarios.sqs_Scenario_SendReceiveBatch.start-->
148+
<!--custom.scenarios.sqs_Scenario_SendReceiveBatch.end-->
149+
133150
#### Use the Amazon SQS Java Messaging Library to work with the JMS interface
134151

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

0 commit comments

Comments
 (0)