TransactionContext Class

  • java.lang.Object
    • com.microsoft.azure.servicebus.TransactionContext

public class TransactionContext

Represents an active servicebus transaction. A transaction is initiated by calling startTransactionAsync(). A transaction can result in commit or rollback. To commit, call endTransactionAsync(TransactionContext transaction, boolean commit) with commit = true To rollback, call endTransactionAsync(TransactionContext transaction, boolean commit) with commit = false

Field Summary

Modifier and Type Field and Description
static TransactionContext NULL_TXN

Constructor Summary

Constructor Description
TransactionContext(ByteBuffer txnId, MessagingFactory messagingFactory)

Method Summary

Modifier and Type Method and Description
void commit()

Commits the transaction

CompletableFuture<Void> commitAsync()

Asynchronously commits the transaction

ByteBuffer getTransactionId()

Represents the service-side transactionID

void notifyTransactionCompletion(boolean commit)

This is not to be called by the user.

void rollback()

Rollback the transaction

CompletableFuture<Void> rollbackAsync()

Asynchronously rollback the transaction.

String toString()

Methods inherited from java.lang.Object

Field Details

NULL_TXN

public static TransactionContext NULL_TXN

Constructor Details

TransactionContext

public TransactionContext(ByteBuffer txnId, MessagingFactory messagingFactory)

Parameters:

txnId
messagingFactory

Method Details

commit

public void commit()

Commits the transaction

Throws:

ServiceBusException - if Commit failed

InterruptedException

- if Commit failed

commitAsync

public CompletableFuture commitAsync()

Asynchronously commits the transaction

Returns:

a CompletableFuture for the commit operation

getTransactionId

public ByteBuffer getTransactionId()

Represents the service-side transactionID

Returns:

transaction ID

notifyTransactionCompletion

public void notifyTransactionCompletion(boolean commit)

This is not to be called by the user.

Parameters:

commit - true indicates success and false for rollback

rollback

public void rollback()

Rollback the transaction

Throws:

ServiceBusException - if rollback failed

InterruptedException

- if rollback failed

rollbackAsync

public CompletableFuture rollbackAsync()

Asynchronously rollback the transaction.

Returns:

a CompletableFuture for the rollback operation

toString

public String toString()

Overrides:

TransactionContext.toString()

Applies to