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
+39-93Lines changed: 39 additions & 93 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1348,9 +1348,8 @@ public SqsMessageListenerContainerFactory<Object> defaultSqsListenerContainerFac
1348
1348
----
1349
1349
1350
1350
==== Exponential Backoff Error Handler
1351
-
This error handler implements an exponential backoff strategy for retrying failed SQS message processing.
1352
-
1353
-
The backoff duration is computed using the `ApproximateReceiveCount` message attribute, applying an exponential function to determine the delay. Once calculated, the handler sets the message's visibility timeout to the computed backoff value, postponing the message's reprocessing accordingly.
1351
+
Implements exponential backoff for retrying failed SQS message processing. The base backoff is computed from `ApproximateReceiveCount` as
1352
+
`initialVisibilityTimeoutSeconds * multiplier^(receiveCount - 1)`, capped by `maxVisibilityTimeoutSeconds`.
1354
1353
1355
1354
[cols="2,3,1,1"]
1356
1355
|===
@@ -1362,7 +1361,7 @@ The backoff duration is computed using the `ApproximateReceiveCount` message att
1362
1361
1363
1362
NOTE: The maximum visibility timeout allowed by SQS is 43200 seconds (12 hours). If the value provided to the `maxVisibilityTimeoutSeconds` parameter exceeds this limit, an `IllegalArgumentException` will be thrown.
1364
1363
1365
-
When using auto-configured factory, simply declare a `@Bean` and the error handler will be set
1364
+
When using the auto-configured factory, a single `@Bean` can be declared and the error handler will be set:
1366
1365
1367
1366
[source, java]
1368
1367
----
@@ -1377,32 +1376,23 @@ public ExponentialBackoffErrorHandler<Object> asyncErrorHandler() {
1377
1376
}
1378
1377
----
1379
1378
1380
-
Alternatively, `ExponentialBackoffErrorHandler` can be set in the `MessageListenerContainerFactory` or directly in the `MessageListenerContainer`:
1379
+
Alternatively, set it via `SqsMessageListenerContainerFactory#errorHandler(...)` or directly on a container if configuring programmatically.
1381
1380
1382
-
[source, java]
1383
-
----
1384
-
@Bean
1385
-
public SqsMessageListenerContainerFactory<Object> defaultSqsListenerContainerFactory() {
Jitter randomizes the final visibility timeout derived from the exponential calculation to avoid synchronized retries ("thundering herd"). It can be configured on the builder via `jitter(...)`.
1383
+
1384
+
`ExponentialBackoffErrorHandler` supports the following strategies:
1385
+
1386
+
- `Jitter.NONE` (default): no randomization; uses the exact exponential timeout.
1387
+
- `Jitter.FULL`: picks a random value uniformly in [0, timeout].
1388
+
- `Jitter.HALF`: picks a random value uniformly in [ceil(timeout/2), timeout].
1398
1389
1399
-
==== Exponential Backoff Full Jitter Error Handler
1400
-
This error handler applies an exponential backoff strategy with *full jitter*
1401
-
when retrying failed message processing. After calculating the exponential
1402
-
visibility timeout using the `ApproximateReceiveCount` message attribute, a
1403
-
random value between zero and the computed timeout is selected. The selected
1404
-
value becomes the new visibility timeout, spreading retries and helping to
1405
-
avoid spikes caused by synchronized retries.
1390
+
The random source can be overridden with `randomSupplier(...)`.
1391
+
1392
+
====== Full Jitter
1393
+
Applies exponential backoff with *full jitter* when retrying failed message processing. After calculating the exponential
1394
+
visibility timeout using the `ApproximateReceiveCount` message attribute, a random value between zero and the computed timeout is selected.
1395
+
The selected value becomes the new visibility timeout, spreading retries and helping to avoid spikes caused by synchronized retries.
1406
1396
1407
1397
[cols="2,3,1,1"]
1408
1398
|===
@@ -1421,47 +1411,24 @@ NOTE: The maximum visibility timeout allowed by SQS is 43200 seconds (12 hours).
1421
1411
If the value provided to the `maxVisibilityTimeoutSeconds` parameter exceeds
1422
1412
this limit, an `IllegalArgumentException` will be thrown.
1423
1413
1424
-
When using auto-configured factory, simply declare a `@Bean` and the error
1425
-
handler will be set
1414
+
To enable full jitter, `jitter(Jitter.FULL)` should be set on the builder:
1426
1415
1427
1416
[source, java]
1428
1417
----
1429
-
@Bean
1430
-
public ExponentialBackoffErrorHandlerWithFullJitter<Object> asyncErrorHandler() {
Copy file name to clipboardExpand all lines: spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/listener/errorhandler/ExponentialBackoffErrorHandler.java
0 commit comments