Class PulsarTransactionManager

java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.pulsar.transaction.PulsarTransactionManager
All Implemented Interfaces:
Serializable, PulsarAwareTransactionManager, org.springframework.transaction.ConfigurableTransactionManager, org.springframework.transaction.PlatformTransactionManager, org.springframework.transaction.TransactionManager

public class PulsarTransactionManager extends org.springframework.transaction.support.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
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager

    org.springframework.transaction.support.AbstractPlatformTransactionManager.SuspendedResourcesHolder
  • Field Summary

    Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager

    logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
  • Constructor Summary

    Constructors
    Constructor
    Description
    PulsarTransactionManager(org.apache.pulsar.client.api.PulsarClient pulsarClient)
    Create a new transaction manager.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition)
     
    protected void
     
    protected void
    doCommit(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected Object
     
    protected void
    doResume(Object transaction, Object suspendedResources)
     
    protected void
    doRollback(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected void
    doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected Object
    doSuspend(Object transaction)
     
    org.apache.pulsar.client.api.PulsarClient
    Get the Pulsar client.
    protected boolean
     

    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 interface PulsarAwareTransactionManager
      Returns:
      the Pulsar client
    • doGetTransaction

      protected Object doGetTransaction()
      Specified by:
      doGetTransaction in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • isExistingTransaction

      protected boolean isExistingTransaction(Object transaction)
      Overrides:
      isExistingTransaction in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doBegin

      protected void doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition)
      Specified by:
      doBegin in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doSuspend

      protected Object doSuspend(Object transaction)
      Overrides:
      doSuspend in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doResume

      protected void doResume(Object transaction, Object suspendedResources)
      Overrides:
      doResume in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doCommit

      protected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status)
      Specified by:
      doCommit in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doRollback

      protected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status)
      Specified by:
      doRollback in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doSetRollbackOnly

      protected void doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
      Overrides:
      doSetRollbackOnly in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doCleanupAfterCompletion

      protected void doCleanupAfterCompletion(Object transaction)
      Overrides:
      doCleanupAfterCompletion in class org.springframework.transaction.support.AbstractPlatformTransactionManager