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
Add package-info.java
Increase Unit Test Coverage
Combine Acknowledgement Interfaces
Support more than 10 maxMessagesPerPoll
Add AcknowledgementOrdering.ORDERED_BY_GROUP
Add BatchAcknowledgement
Add AsyncBatchAcknowledgement
Add tests
Add AcknowledgementResultCallback
Add tests
Replace ExpressionHelper with StringValueResolver
Add maxMessagesPerPoll to SqsListener
Disable container reuse for TC
Use ApplicationContextRunner in tests
Address review suggestions
Clean up tests
Fix InterceptorIntegrationTest
Make ComponentFactory a collection
Add Unit Tests
Apply Spotless
IMPORTANT: Currently, batch listeners only support `List<MyPojo>` and `List<Message<MyPojo>>` method arguments.
402
-
Other arguments can be found as headers in the `Message<MyPojo>` instances and can be extracted through the `getHeader` method.
400
+
IMPORTANT: Batch listeners support a single `List<MyPojo>` and `List<Message<MyPojo>>` method arguments, and an optional `BatchAcknowledgement` or `AsyncBatchAcknowledgement` arguments.
401
+
`MessageHeaders` should be extracted from the `Message` instances through the `getHeaders()` method.
403
402
404
403
==== Batch Processing
405
404
406
405
All message processing interfaces have both `single message` and `batch` methods.
407
-
This means the same set of components can be used to process both single and batch methods, and can share logic where applicable.
406
+
This means the same set of components can be used to process both single and batch methods, and share logic where applicable.
408
407
409
408
When batch mode is enabled, the framework will serve the entire result of a poll to the listener.
409
+
If a value greater than 10 is provided for `maxMessagesPerPoll`, the result of multiple polls will be combined and up to the respective amount of messages will be served to the listener.
410
410
411
-
To enable batch processing using `@SqsListener`, declare a `List<MyPojo>` or `List<Message<MyPojo>>` method argument in the listener method.
411
+
To enable batch processing using `@SqsListener`, a single `List<MyPojo>` or `List<Message<MyPojo>>` method argument should be provided in the listener method.
412
+
The listener method can also have an optional `BatchAcknowledgement` argument for `AcknowledgementMode.MANUAL`.
412
413
413
-
IMPORTANT: Currently, when declaring batch mode this way, no other arguments can be added to the method signature.
414
-
If any metadata is required, the `List<Message<MyPojo>>` variant should be used, then the headers can be checked to retrieve such information.
415
-
The `SqsHeaders.SQS_ACKNOWLEDGMENT_CALLBACK_HEADER` will contain the `AcknowldgementCallback` you can use to manually acknowledge the messages in `AcknowledgementMode.MANUAL`.
416
-
If acknowledgement batching is being used, acknowledgements will be batched instead of executing immediately.
417
-
See <<Acknowledging Messages>> for more information on `Acknowledging messages`
418
-
419
-
To configure a batch processing at factory or container level, set `MessageDeliveryStrategy.BATCH` in the `ContainerOptions`, in the factory or container.
420
-
This will affect manually created containers.
421
-
Containers created from `@SqsListener` annotations will override this setting with whether they contain a `List<Pojoj>` or `List<Message<Pojo>>` argument.
414
+
Alternatively, `ContainerOptions` can be set to `ListenerMode.BATCH` in the `ContainerOptions` in the factory or container.
422
415
423
416
NOTE: The same factory can be used to create both `single message` and `batch` containers for `@SqsListener` methods.
424
417
425
418
IMPORTANT: In case the same factory is shared by both delivery methods, any supplied `ErrorHandler`, `MessageInterceptor` or `MessageListener` should implement the proper methods.
426
419
427
-
IMPORTANT: If batch mode is enabled, make sure all components being used have the necessary `batch` methods implemented, otherwise an error may occur.
428
420
429
421
==== Container Options
430
422
@@ -512,9 +504,12 @@ For batching acknowledgements a message is considered as no longer inflight when
512
504
See <<Acknowledging Messages>>.
513
505
514
506
|<<maxMessagesPerPoll>>
515
-
|1 - 10
507
+
|1 - `Integer.MAX_VALUE`
516
508
|10
517
509
|The maximum number of messages that will be received by a poll to a SQS queue in this container.
510
+
If a value greater than 10 is provided, the result of multiple polls
511
+
will be combined, which can be useful for batch listeners.
512
+
518
513
See AWS documentation for more information.
519
514
520
515
|<<pollTimeout>>
@@ -543,7 +538,7 @@ See <<Container Lifecycle>>.
543
538
|Configures the backpressure strategy to be used by the container.
544
539
See <<Configuring BackPressureMode>>.
545
540
546
-
|`messageDeliveryStrategy`
541
+
|`listenerMode`
547
542
|`SINGLE_MESSAGE`, `BATCH`
548
543
|`SINGLE_MESSAGE`
549
544
|Configures whether this container will use `single message` or `batch` listeners.
@@ -996,11 +991,11 @@ public class SqsApplication {
996
991
}
997
992
----
998
993
999
-
1000
994
=== Acknowledging Messages
1001
995
1002
996
In `SQS` acknowledging a message is the same as deleting the message from the queue.
1003
997
A number of `Acknowledgement` strategies are available and can be configured via `ContainerOptions`.
998
+
Optionally, a callback action can be added to be executed after either a successful or failed acknowledgement.
1004
999
1005
1000
Here's an example of a possible configuration:
1006
1001
@@ -1052,14 +1047,72 @@ IMPORTANT: If an immediate acknowledging triggers an error, message processing i
1052
1047
1053
1048
==== Manual Acknowledgement
1054
1049
1050
+
Acknowledgements can be handled manually by setting `AcknowledgementMode.MANUAL` in the `ContainerOptions`.
1051
+
1055
1052
Manual acknowledgement can be used in conjunction with acknowledgement batching - the message will be queued for acknowledgement but won't be executed until one of the above criteria is met.
1056
1053
1057
1054
It can also be used in conjunction with immediate acknowledgement.
1058
1055
1056
+
The following arguments can be used in listener methods to manually acknowledge:
1057
+
1058
+
===== `Acknowledgement`
1059
+
1060
+
The `Acknowledgement` interface can be used to acknowledge messages in `ListenerMode.SINGLE_MESSAGE`.
1061
+
1062
+
```java
1063
+
public interface Acknowledgement {
1064
+
1065
+
/**
1066
+
* Acknowledge the message.
1067
+
*/
1068
+
void acknowledge();
1069
+
1070
+
/**
1071
+
* Asynchronously acknowledge the message.
1072
+
*/
1073
+
CompletableFuture<Void> acknowledgeAsync();
1074
+
1075
+
}
1076
+
```
1077
+
1078
+
===== `BatchAcknowledgement`
1079
+
1080
+
The `BatchAcknowledgement` interface can be used to acknowledge messages in `ListenerMode.BATCH`.
1081
+
1082
+
The `acknowledge(Collection<Message<T>)` method enables acknowledging partial batches.
1083
+
1084
+
```java
1085
+
public interface BatchAcknowledgement<T> {
1086
+
1087
+
/**
1088
+
* Acknowledge all messages from the batch.
1089
+
*/
1090
+
void acknowledge();
1091
+
1092
+
/**
1093
+
* Asynchronously acknowledge all messages from the batch.
- `PARALLEL` - Acknowledges the messages as soon as one of the above criterias is met - many acknowledgement calls can be made in parallel.
1062
-
- `ORDERED` - One batch of acknowledgements will only be executed after the previous one is completed, ensuring `FIFO` ordering of acknowledgements.
1112
+
- `PARALLEL` - Acknowledges the messages as soon as one of the above criteria is met - many acknowledgement calls can be made in parallel.
1113
+
- `ORDERED` - One batch of acknowledgements will be executed after the previous one is completed, ensuring `FIFO` ordering for `batching` acknowledgements.
1114
+
- `ORDERED_BY_GROUP` - One batch of acknowledgements will be executed after the previous one for the same group is completed, ensuring `FIFO` ordering of acknowledgements with parallelism between message groups.
1115
+
Only available for `FIFO` queues.
1063
1116
1064
1117
1065
1118
==== Acknowledgement Defaults
@@ -1078,15 +1131,62 @@ The defaults for acknowledging differ for `Standard` and `FIFO` SQS queues.
1078
1131
1079
1132
NOTE: PARALLEL is the default for FIFO because ordering is guaranteed for processing.
1080
1133
This assures no messages from a given `MessageGroup` will be polled until the previous batch is acknowledged.
1134
+
Implementations of this interface will be executed after an acknowledgement execution completes with either success or failure.
1135
+
1136
+
==== Acknowledgement Result Callback
1137
+
1138
+
The framework offers the `AcknowledgementResultCallback` and `AsyncAcknowledgementCallback` interfaces that can be added to a `SqsMessageListenerContainer` or `SqsMessageListenerContainerFactory`.
1139
+
1140
+
```java
1141
+
public interface AcknowledgementResultCallback<T> {
NOTE: When `immediate acknowledgement` is set, as is the default for `FIFO` queues, the callback will be executed **before** the next message in the batch is processed, and next message processing will wait for the callback completion.
1178
+
This can be useful for taking action such as retrying to delete the messages, or stopping the container to prevent duplicate processing in case an acknowledgement fails in a FIFO queue.
1179
+
For `batch parallel processing`, as is the default for `Standard` queues the callback execution happens asynchronously.
1180
+
1081
1181
1082
1182
=== Global Configuration for @SqsListeners
1083
1183
1084
-
A set of configurations can be set for all containers from `@SqsListener` by providing `SqsListenerCustomizer` beans.
1184
+
A set of configurations can be set for all containers from `@SqsListener` by providing `SqsListenerConfigurer` beans.
1085
1185
1086
1186
[source, java]
1087
1187
----
1088
1188
@FunctionalInterface
1089
-
public interface SqsListenerCustomizer {
1189
+
public interface SqsListenerConfigurer {
1090
1190
1091
1191
void configure(EndpointRegistrar registrar);
1092
1192
@@ -1111,12 +1211,12 @@ A simple example would be:
NOTE: Many `SqsListenerCustomizer` beans can be registered in the context.
1219
+
NOTE: Any number of `SqsListenerConfigurer` beans can be registered in the context.
1120
1220
All instances will be looked up at application startup and iterated through.
1121
1221
1122
1222
=== Message Processing Throughput
@@ -1138,7 +1238,7 @@ When using immediate acknowledgement, a message is considered as no longer infli
1138
1238
1139
1239
1140
1240
===== maxMessagesPerPoll
1141
-
Set in `ContainerOptions`.
1241
+
Set in `ContainerOptions` or the `@SqsListener` annotation.
1142
1242
Represents the maximum number of messages returned by a single poll to a SQS queue, to a maximum of 10.
1143
1243
This value has to be less than or equal to `maxInflightMessagesPerQueue`.
1144
1244
Defaults to 10.
@@ -1209,11 +1309,10 @@ Otherwise, a `sync` interface should be used.
1209
1309
1210
1310
==== Providing a TaskExecutor
1211
1311
1212
-
The default `TaskExecutor` is a `ThreadPoolTaskExecutor`, and a different `componentTaskExecutor` can be set in the `ContainerOptions`.
1312
+
The default `TaskExecutor` is a `ThreadPoolTaskExecutor`, and a different `componentTaskExecutor` supplier can be set in the `ContainerOptions`.
1213
1313
1214
1314
When providing a custom executor, it's important that it's configured to support all threads that will be created, which should be (maxInflightMessagesPerQueue * total number of queues).
1215
-
When set as a `MessageListenerContainerFactory` options, it's important to consider all the containers it will be applied to.
1216
-
Also, to avoid excessive thread hopping, a `MessageExecutionThreadFactory` should be set to the executor.
1315
+
Also, to avoid unnecessary thread hopping between blocking components, a `MessageExecutionThreadFactory` should be set to the executor.
1217
1316
1218
1317
If setting the `ThreadFactory` is not possible, it's advisable to allow for extra threads in the thread pool to account for the time between a new thread is requested and the previous thread is released.
Copy file name to clipboardExpand all lines: spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/sqs/SqsAutoConfiguration.java
0 commit comments