Package com.microsoft.azure.servicebus
Class TransactionContext
- java.lang.Object
-
- com.microsoft.azure.servicebus.TransactionContext
-
public class TransactionContext extends Object
Represents an active servicebus transaction. A transaction is initiated by callingMessagingFactory.startTransactionAsync()
. A transaction can result in commit or rollback. To commit, callMessagingFactory.endTransactionAsync(TransactionContext, boolean)
withcommit = true
To rollback, callMessagingFactory.endTransactionAsync(TransactionContext, boolean)
withcommit = false
-
-
Field Summary
Fields Modifier and Type Field Description static TransactionContext
NULL_TXN
-
Constructor Summary
Constructors Constructor Description TransactionContext(ByteBuffer txnId, MessagingFactory messagingFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
commit()
Commits the transactionCompletableFuture<Void>
commitAsync()
Asynchronously commits the transactionByteBuffer
getTransactionId()
Represents the service-side transactionIDvoid
notifyTransactionCompletion(boolean commit)
This is not to be called by the user.void
rollback()
Rollback the transactionCompletableFuture<Void>
rollbackAsync()
Asynchronously rollback the transaction.String
toString()
-
-
-
Field Detail
-
NULL_TXN
public static TransactionContext NULL_TXN
-
-
Constructor Detail
-
TransactionContext
public TransactionContext(ByteBuffer txnId, MessagingFactory messagingFactory)
-
-
Method Detail
-
getTransactionId
public ByteBuffer getTransactionId()
Represents the service-side transactionID- Returns:
- transaction ID
-
commit
public void commit() throws ServiceBusException, InterruptedException
Commits the transaction- Throws:
ServiceBusException
- if Commit failedInterruptedException
- if the current thread was interrupted while waiting
-
commitAsync
public CompletableFuture<Void> commitAsync()
Asynchronously commits the transaction- Returns:
- a CompletableFuture for the commit operation
-
rollback
public void rollback() throws ServiceBusException, InterruptedException
Rollback the transaction- Throws:
ServiceBusException
- if rollback failedInterruptedException
- if the current thread was interrupted while waiting
-
rollbackAsync
public CompletableFuture<Void> rollbackAsync()
Asynchronously rollback the transaction.- Returns:
- a CompletableFuture for the rollback operation
-
notifyTransactionCompletion
public void notifyTransactionCompletion(boolean commit)
This is not to be called by the user.- Parameters:
commit
- true indicates success and false for rollback
-
-