public final class ServiceBusTransactionContext extends Object
A transaction times out after 2 minutes. The transaction timer starts when the first operation in the transaction starts.
Creating and using a transaction
// This mono creates a transaction and caches the output value, so we can associate operations with the // transaction. It does not cache the value if it is an error or completes with no items, effectively retrying // the operation. Mono<ServiceBusTransactionContext> transactionContext = receiver.createTransaction() .cache(value -> Duration.ofMillis(Long.MAX_VALUE), error -> Duration.ZERO, () -> Duration.ZERO); transactionContext.flatMap(transaction -> { // Process messages and associate operations with the transaction. Mono<Void> operations = Mono.when( receiver.receiveDeferredMessage(sequenceNumber).flatMap(message -> receiver.complete(message, new CompleteOptions().setTransactionContext(transaction))), receiver.abandon(receivedMessage, new AbandonOptions().setTransactionContext(transaction))); // Finally, either commit or rollback the transaction once all the operations are associated with it. return operations.flatMap(transactionOperations -> receiver.commitTransaction(transaction)); });
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
getTransactionId()
Gets the transaction id.
|
public ByteBuffer getTransactionId()
Copyright © 2021 Microsoft Corporation. All rights reserved.