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
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