Class RabbitTransactionManager
- All Implemented Interfaces:
Serializable,InitializingBean,ConfigurableTransactionManager,PlatformTransactionManager,ResourceTransactionManager,TransactionManager
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
AbstractPlatformTransactionManager.SuspendedResourcesHolder -
Field Summary
Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new RabbitTransactionManager for bean-style usage.RabbitTransactionManager(ConnectionFactory connectionFactory) Create a new RabbitTransactionManager, given a ConnectionFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoidMake sure the ConnectionFactory has been set.protected voiddoBegin(Object transaction, TransactionDefinition definition) protected voiddoCleanupAfterCompletion(Object transaction) protected voiddoCommit(DefaultTransactionStatus status) protected Objectprotected voidprotected voiddoRollback(DefaultTransactionStatus status) protected voidprotected Objectprotected booleanisExistingTransaction(Object transaction) voidsetConnectionFactory(ConnectionFactory connectionFactory) Methods inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionExecutionListeners, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, prepareForCommit, prepareSynchronization, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionExecutionListeners, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransactionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.transaction.ConfigurableTransactionManager
addListenerMethods inherited from interface org.springframework.transaction.PlatformTransactionManager
commit, getTransaction, rollback
-
Constructor Details
-
RabbitTransactionManager
public RabbitTransactionManager()Create a new RabbitTransactionManager for bean-style usage.Note: The ConnectionFactory has to be set before using the instance. This constructor can be used to prepare a RabbitTemplate via a BeanFactory, typically setting the ConnectionFactory via setConnectionFactory.
Turns off transaction synchronization by default, as this manager might be used alongside a datastore-based Spring transaction manager like DataSourceTransactionManager, which has stronger needs for synchronization. Only one manager is allowed to drive synchronization at any point of time.
-
RabbitTransactionManager
Create a new RabbitTransactionManager, given a ConnectionFactory.- Parameters:
connectionFactory- the ConnectionFactory to use
-
-
Method Details
-
setConnectionFactory
- Parameters:
connectionFactory- the connectionFactory to set
-
getConnectionFactory
- Returns:
- the connectionFactory
-
afterPropertiesSet
public void afterPropertiesSet()Make sure the ConnectionFactory has been set.- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
getResourceFactory
- Specified by:
getResourceFactoryin interfaceResourceTransactionManager
-
doGetTransaction
- Specified by:
doGetTransactionin classAbstractPlatformTransactionManager
-
isExistingTransaction
- Overrides:
isExistingTransactionin classAbstractPlatformTransactionManager
-
doBegin
- Specified by:
doBeginin classAbstractPlatformTransactionManager
-
doSuspend
- Overrides:
doSuspendin classAbstractPlatformTransactionManager
-
doResume
- Overrides:
doResumein classAbstractPlatformTransactionManager
-
doCommit
- Specified by:
doCommitin classAbstractPlatformTransactionManager
-
doRollback
- Specified by:
doRollbackin classAbstractPlatformTransactionManager
-
doSetRollbackOnly
- Overrides:
doSetRollbackOnlyin classAbstractPlatformTransactionManager
-
doCleanupAfterCompletion
- Overrides:
doCleanupAfterCompletionin classAbstractPlatformTransactionManager
-