Class RabbitTransactionManager

java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.amqp.rabbit.transaction.RabbitTransactionManager
All Implemented Interfaces:
Serializable, InitializingBean, ConfigurableTransactionManager, PlatformTransactionManager, ResourceTransactionManager, TransactionManager

public class RabbitTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager, InitializingBean
PlatformTransactionManager implementation for a single Rabbit ConnectionFactory. Binds a Rabbit Channel from the specified ConnectionFactory to the thread, potentially allowing for one thread-bound channel per ConnectionFactory.

This local strategy is an alternative to executing Rabbit 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 Rabbit resources via ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactory, boolean) instead of a standard Connection.createChannel(boolean) call with subsequent Channel creation. Spring's RabbitTemplate will autodetect a thread-bound Channel and automatically participate in it.

The use of CachingConnectionFactory as a target for this transaction manager is strongly recommended. CachingConnectionFactory uses a single Rabbit Connection for all Rabbit access in order to avoid the overhead of repeated Connection creation, as well as maintaining a cache of Channels. Each transaction will then share the same Rabbit Connection, while still using its own individual Rabbit Channel.

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:
Dave Syer
See Also: