Class PulsarTransactionManager
java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.pulsar.transaction.PulsarTransactionManager
- All Implemented Interfaces:
Serializable
,PulsarAwareTransactionManager
,ConfigurableTransactionManager
,PlatformTransactionManager
,TransactionManager
public class PulsarTransactionManager
extends AbstractPlatformTransactionManager
implements PulsarAwareTransactionManager
Binds a
native Pulsar transaction
from the specified
PulsarClient
to the current thread, allowing for one transaction per thread per
Pulsar client.
This transaction manager 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 Pulsar resources via
PulsarTransactionUtils.obtainResourceHolder(org.apache.pulsar.client.api.PulsarClient, java.time.Duration)
. The PulsarTemplate
will
auto-detect a thread-bound transaction and automatically participate in it.
Transaction synchronization is turned off by default, as this manager might be used
alongside a datastore-based Spring transaction manager such as the JDBC
DataSourceTransactionManager
, which has stronger needs for synchronization.
- Since:
- 1.1.0
- Author:
- Chris Bono
- 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
ConstructorDescriptionPulsarTransactionManager
(org.apache.pulsar.client.api.PulsarClient pulsarClient) Create a new transaction manager. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doBegin
(Object transaction, TransactionDefinition definition) protected void
doCleanupAfterCompletion
(Object transaction) protected void
doCommit
(DefaultTransactionStatus status) protected Object
protected void
protected void
doRollback
(DefaultTransactionStatus status) protected void
protected Object
org.apache.pulsar.client.api.PulsarClient
Get the Pulsar client.protected boolean
isExistingTransaction
(Object transaction) 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, useSavepointForNestedTransaction
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.transaction.ConfigurableTransactionManager
addListener
Methods inherited from interface org.springframework.transaction.PlatformTransactionManager
commit, getTransaction, rollback
-
Constructor Details
-
PulsarTransactionManager
public PulsarTransactionManager(org.apache.pulsar.client.api.PulsarClient pulsarClient) Create a new transaction manager.- Parameters:
pulsarClient
- the pulsar client used to construct the backing Pulsar native transactions.
-
-
Method Details
-
getPulsarClient
public org.apache.pulsar.client.api.PulsarClient getPulsarClient()Description copied from interface:PulsarAwareTransactionManager
Get the Pulsar client.- Specified by:
getPulsarClient
in interfacePulsarAwareTransactionManager
- Returns:
- the Pulsar client
-
doGetTransaction
- Specified by:
doGetTransaction
in classAbstractPlatformTransactionManager
-
isExistingTransaction
- Overrides:
isExistingTransaction
in classAbstractPlatformTransactionManager
-
doBegin
- Specified by:
doBegin
in classAbstractPlatformTransactionManager
-
doSuspend
- Overrides:
doSuspend
in classAbstractPlatformTransactionManager
-
doResume
- Overrides:
doResume
in classAbstractPlatformTransactionManager
-
doCommit
- Specified by:
doCommit
in classAbstractPlatformTransactionManager
-
doRollback
- Specified by:
doRollback
in classAbstractPlatformTransactionManager
-
doSetRollbackOnly
- Overrides:
doSetRollbackOnly
in classAbstractPlatformTransactionManager
-
doCleanupAfterCompletion
- Overrides:
doCleanupAfterCompletion
in classAbstractPlatformTransactionManager
-