Skip to content

Commit 6a8fb64

Browse files
committed
Document exception retry behavior for Kafka transactions
Signed-off-by: Soby Chacko <[email protected]>
1 parent 463ca22 commit 6a8fb64

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/modules/ROOT/pages/kafka/kafka-binder/transactional.adoc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,56 @@ public static class Sender {
5151
If you wish to synchronize producer-only transactions with those from some other transaction manager, use a `ChainedTransactionManager`.
5252

5353
IMPORTANT: If you deploy multiple instances of your application, each instance needs a unique `transactionIdPrefix`.
54+
55+
== Exception Retry Behavior in Kafka Transactions
56+
57+
=== Configuring Transaction Rollback Retry Behavior
58+
59+
When processing messages within a Kafka transaction, you can configure which exceptions should be retried after a transaction rollback using the `defaultRetryable` property and the `retryableExceptions` map.
60+
61+
=== Default Retry Behavior
62+
63+
The `DefaultAfterRollbackProcessor` determines which exceptions trigger a retry after a transaction rollback.
64+
By default, all exceptions will be retried, but you can modify this behavior:
65+
66+
[source,yaml]
67+
----
68+
spring:
69+
cloud:
70+
stream:
71+
kafka:
72+
bindings:
73+
<binding-name>:
74+
consumer:
75+
defaultRetryable: false # Change default to NOT retry exceptions
76+
----
77+
78+
When `defaultRetryable` is set to `false`, the `DefaultAfterRollbackProcessor` will be configured with `defaultFalse(true)`, meaning exceptions will not be retried unless explicitly configured as retryable.
79+
80+
=== Exception-Specific Configuration
81+
82+
For fine-grained control, you can specify retry behavior for individual exception types:
83+
84+
[source,yaml]
85+
----
86+
spring:
87+
cloud:
88+
stream:
89+
kafka:
90+
bindings:
91+
<binding-name>:
92+
consumer:
93+
retryableExceptions:
94+
java.lang.IllegalStateException: true # Always retry this exception
95+
java.lang.IllegalArgumentException: false # Never retry this exception
96+
----
97+
98+
The `DefaultAfterRollbackProcessor` will use `addRetryableExceptions()` for exceptions marked as `true` and `addNotRetryableExceptions()` for those marked as `false`.
99+
These exception-specific configurations take precedence over the default behavior.
100+
101+
=== Implementation Details
102+
103+
* Only exception types (subclasses of `Exception`) can be configured in `retryableExceptions` when using transactions
104+
* An `IllegalArgumentException` will be thrown if non-Exception types are specified
105+
* The `DefaultAfterRollbackProcessor` is only configured when transactions are enabled and batch mode is disabled
106+
* This configuration ensures that the transaction retry behavior is consistent with non-transactional retry handling

0 commit comments

Comments
 (0)