All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.messaging.servicebus.ServiceBusTransactionContext Maven / Gradle / Ivy

There is a newer version: 7.18.0-beta.1
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.messaging.servicebus;

import com.azure.core.annotation.Immutable;

import java.nio.ByteBuffer;

/**
 * Represents transaction in service. This object just contains transaction id. Transaction management operations
 * like create transaction, rollback, and commit operation need to be done using the sender or receiver clients.
 * 

* 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));
 * });
 * 
* * @see ServiceBusReceiverClient#createTransaction() * @see ServiceBusReceiverAsyncClient#createTransaction() * @see ServiceBusSenderClient#createTransaction() * @see ServiceBusSenderAsyncClient#createTransaction() * @see Transaction * Overview */ @Immutable public final class ServiceBusTransactionContext { private final ByteBuffer transactionId; ServiceBusTransactionContext(ByteBuffer transactionId) { this.transactionId = transactionId; } /** * Gets the transaction id. * * @return transaction ID */ public ByteBuffer getTransactionId() { return this.transactionId; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy