You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/sqs.adoc
+131Lines changed: 131 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -806,6 +806,130 @@ NOTE: The same factory can be used to create both `single message` and `batch` c
806
806
807
807
IMPORTANT: In case the same factory is shared by both delivery methods, any supplied `ErrorHandler`, `MessageInterceptor` or `MessageListener` should implement the proper methods.
808
808
809
+
==== Automatic Batching with AWS SDK
810
+
811
+
Spring Cloud AWS supports automatic message batching using AWS SDK's `SqsAsyncBatchManager`. This feature optimizes SQS operations by automatically batching requests under the hood to improve performance and reduce AWS API calls.
812
+
813
+
IMPORTANT: This is different from the <<Batch Processing,Batch Processing>> feature described above. Batch Processing refers to processing multiple messages in a single listener method call, while Automatic Batching refers to the AWS SDK automatically combining multiple SQS API calls into batched requests for efficiency.
814
+
815
+
===== Enabling Automatic Batching
816
+
817
+
To enable automatic batching, set the following property:
818
+
819
+
[source,properties]
820
+
----
821
+
spring.cloud.aws.sqs.batch.enabled=true
822
+
----
823
+
824
+
When enabled, Spring Cloud AWS will automatically wrap the `SqsAsyncClient` with a `BatchingSqsClientAdapter` that uses `SqsAsyncBatchManager` internally.
825
+
826
+
===== Configuration Properties
827
+
828
+
The following properties can be used to configure the batching behavior:
829
+
830
+
[source,properties]
831
+
----
832
+
# Enable automatic batching (default: false)
833
+
spring.cloud.aws.sqs.batch.enabled=true
834
+
835
+
# Maximum number of messages in a batch (default: AWS SDK default, max: 10)
WARNING: When using automatic batching, operations are processed asynchronously by the AWS SDK. This means that a method call may return successfully, but the actual request to AWS SQS might fail later during the batching process. This can result in **false positives** where operations appear to succeed locally but fail during transmission.
857
+
858
+
Applications should:
859
+
860
+
- **Always handle the returned `CompletableFuture`** to detect actual transmission errors
861
+
- **Implement appropriate error handling and monitoring** to detect delayed failures
862
+
- **Consider retry mechanisms** for critical operations
863
+
864
+
IMPORTANT: **Batch Manager Bypass**: The AWS SDK batch manager will bypass batching and send regular asynchronous requests when `receiveMessage` is called with any of the following parameters:
865
+
866
+
- `messageAttributeNames`
867
+
- `messageSystemAttributeNames`
868
+
- `messageSystemAttributeNamesWithStrings` (not used in Spring Cloud AWS `ReceiveMessageRequest`)
869
+
- `overrideConfiguration` (not used in Spring Cloud AWS `ReceiveMessageRequest`)
870
+
871
+
When these parameters are used, the performance benefits of batching are lost for those specific requests.
872
+
873
+
**Note**: When using Spring Cloud AWS's automatic batching feature, `SqsTemplate` automatically excludes `messageAttributeNames` and `messageSystemAttributeNames` from individual `receiveMessage` requests to maintain batching efficiency. These attributes should be configured globally in the batch configuration instead:
If you need to use different attribute configurations per request, consider disabling automatic batching and using the standard `SqsAsyncClient` instead.
883
+
884
+
Example of proper error handling:
885
+
886
+
[source,java]
887
+
----
888
+
@Service
889
+
public class MessageService {
890
+
891
+
private final SqsTemplate sqsTemplate;
892
+
893
+
public MessageService(SqsTemplate sqsTemplate) {
894
+
this.sqsTemplate = sqsTemplate;
895
+
}
896
+
897
+
public void sendMessage(String queueName, String message) {
Copy file name to clipboardExpand all lines: spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/sqs/SqsAutoConfigurationTest.java
0 commit comments