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
Fixes: #2852
* Provide a way to customize the transactionIdSuffix by providing a new strategy API - `TransactionIdSuffixStrategy`
* PR adds a default implementation for this new API
* Related changes in classes that deal with transactions
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/transactions.adoc
+33-1Lines changed: 33 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -102,11 +102,43 @@ NOTE: If there is a `KafkaTransactionManager` (or synchronized) transaction in p
102
102
Instead, a new "nested" transaction is used.
103
103
104
104
[[transaction-id-prefix]]
105
-
== `transactionIdPrefix`
105
+
== `TransactionIdPrefix`
106
106
107
107
With `EOSMode.V2` (aka `BETA`), the only supported mode, it is no longer necessary to use the same `transactional.id`, even for consumer-initiated transactions; in fact, it must be unique on each instance the same as for producer-initiated transactions.
108
108
This property must have a different value on each application instance.
109
109
110
+
[[transaction-id-suffix-fixed]]
111
+
== `TransactionIdSuffix Fixed`
112
+
113
+
Since 3.2, a new `TransactionIdSuffixStrategy` interface was introduced to manage `transactional.id` suffix.
114
+
The default implementation is `DefaultTransactionIdSuffixStrategy` when setting `maxCache` greater than zero can reuse `transactional.id` within a specific range, otherwise suffixes will be generated on the fly by incrementing a counter.
115
+
When a transaction producer is requested and `transactional.id` all in use, throw a `NoProducerAvailableException`.
116
+
User can then use a `RetryTemplate` configured to retry that exception, with a suitably configured back off.
117
+
118
+
[source,java]
119
+
----
120
+
public static class Config {
121
+
122
+
@Bean
123
+
public ProducerFactory<String, String> myProducerFactory() {
DefaultKafkaProducerFactory<String, String> pf = new DefaultKafkaProducerFactory<>(configs);
128
+
...
129
+
TransactionIdSuffixStrategy ss = new DefaultTransactionIdSuffixStrategy(5);
130
+
pf.setTransactionIdSuffixStrategy(ss);
131
+
return pf;
132
+
}
133
+
134
+
}
135
+
----
136
+
When setting `maxCache` to 5, `transactional.id` is `my.txid.`++`{0-4}`+.
137
+
138
+
IMPORTANT: When using `KafkaTransactionManager` with the `ConcurrentMessageListenerContainer` and enabling `maxCache`, it is necessary to set `maxCache` to a value greater than or equal to `concurrency`.
139
+
If a `MessageListenerContainer` is unable to acquire a `transactional.id` suffix, it will throw a `NoProducerAvailableException`.
140
+
When using nested transactions in the `ConcurrentMessageListenerContainer`, it is necessary to adjust the maxCache setting to handle the increased number of nested transactions.
141
+
110
142
[[tx-template-mixed]]
111
143
== `KafkaTemplate` Transactional and non-Transactional Publishing
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,3 +7,9 @@
7
7
This section covers the changes made from version 3.1 to version 3.2.
8
8
For changes in earlier version, see xref:appendix/change-history.adoc[Change History].
9
9
10
+
[[x32-tiss]]
11
+
=== TransactionIdSuffixStrategy
12
+
13
+
A new `TransactionIdSuffixStrategy` interface was introduced to manage `transactional.id` suffix.
14
+
The default implementation is `DefaultTransactionIdSuffixStrategy` when setting `maxCache` greater than zero can reuse `transactional.id` within a specific range, otherwise suffixes will be generated on the fly by incrementing a counter.
15
+
See xref:kafka/transactions.adoc#transaction-id-suffix-fixed[Fixed TransactionIdSuffix] for more information.
0 commit comments