Class KafkaTransactionManager<K,V>

java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.kafka.transaction.KafkaTransactionManager<K,V>
Type Parameters:
K - the key type.
V - the value type.
All Implemented Interfaces:
Serializable, KafkaAwareTransactionManager<K,V>, PlatformTransactionManager, TransactionManager

public class KafkaTransactionManager<K,V> extends AbstractPlatformTransactionManager implements KafkaAwareTransactionManager<K,V>
PlatformTransactionManager implementation for a single Kafka ProducerFactory. Binds a Kafka producer from the specified ProducerFactory to the thread, potentially allowing for one thread-bound producer per ProducerFactory.

This local strategy is an alternative to executing Kafka operations within, and synchronized with, external transactions. This strategy is not able to provide XA transactions, for example in order to share transactions between messaging and database access.

Application code is required to retrieve the transactional Kafka resources via ProducerFactoryUtils.getTransactionalResourceHolder(ProducerFactory, String, java.time.Duration). Spring's KafkaTemplate will auto detect a thread-bound Producer and automatically participate in it.

The use of DefaultKafkaProducerFactory as a target for this transaction manager is strongly recommended. Because it caches producers for reuse.

Transaction synchronization is turned off by default, as this manager might be used alongside a datastore-based Spring transaction manager such as the JDBC org.springframework.jdbc.datasource.DataSourceTransactionManager, which has stronger needs for synchronization.

Author:
Gary Russell
See Also: