Class PulsarTransactionUtils
java.lang.Object
org.springframework.pulsar.transaction.PulsarTransactionUtils
Provides conveniences for managing Pulsar transactions.
- Since:
- 1.1.0
- Author:
- Chris Bono
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
abort
(org.apache.pulsar.client.api.transaction.Transaction transaction) Aborts a Pulsar transaction asynchronously, logging the outcome at trace level.static PulsarResourceHolder
getResourceHolder
(org.apache.pulsar.client.api.PulsarClient pulsarClient) Get a resource holder that is already synchronized with the current transaction.static boolean
inTransaction
(org.apache.pulsar.client.api.PulsarClient pulsarClient) Determine if the given pulsar client is currently participating in an active transaction.static PulsarResourceHolder
obtainResourceHolder
(org.apache.pulsar.client.api.PulsarClient pulsarClient, Duration timeout) Obtain a resource holder that is synchronized with the current transaction.
-
Method Details
-
inTransaction
public static boolean inTransaction(org.apache.pulsar.client.api.PulsarClient pulsarClient) Determine if the given pulsar client is currently participating in an active transaction. The result will betrue
if the current thread is associated with an actual transaction or if the given pulsar client is already synchronized with the current transaction.- Parameters:
pulsarClient
- the client to check- Returns:
- whether the client is currently participating in an active transaction
-
abort
public static void abort(org.apache.pulsar.client.api.transaction.Transaction transaction) Aborts a Pulsar transaction asynchronously, logging the outcome at trace level.- Parameters:
transaction
- the transaction to abort
-
getResourceHolder
@Nullable public static PulsarResourceHolder getResourceHolder(org.apache.pulsar.client.api.PulsarClient pulsarClient) Get a resource holder that is already synchronized with the current transaction.- Parameters:
pulsarClient
- the client used to obtain the transaction resource- Returns:
- the resource holder
-
obtainResourceHolder
public static PulsarResourceHolder obtainResourceHolder(org.apache.pulsar.client.api.PulsarClient pulsarClient, @Nullable Duration timeout) Obtain a resource holder that is synchronized with the current transaction. If there is already one associated with the current transaction it is returned otherwise a new one is created and associated to the current transaction.- Parameters:
pulsarClient
- the client used to obtain the transaction resourcetimeout
- the max time to wait for the transaction to be completed before it will be aborted or null to use defaults- Returns:
- the resource holder
- Since:
- 1.1.0
-