次の方法で共有


ServiceBusTransactionContext クラス

  • java.lang.Object
    • com.azure.messaging.servicebus.ServiceBusTransactionContext

public final class ServiceBusTransactionContext

サービス内のトランザクションを表します。 このオブジェクトには、トランザクション ID だけが含まれています。トランザクションの作成、ロールバック、コミット操作などのトランザクション管理操作は、送信側または受信側のクライアントを使用して行う必要があります。

トランザクションは 2 分後にタイムアウトになります。 トランザクションの最初の操作が開始されると、トランザクション タイマーが開始されます。

トランザクションの作成と使用

// 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 = asyncReceiver.createTransaction()
     .cache(value -> Duration.ofMillis(Long.MAX_VALUE),
         error -> Duration.ZERO,
         () -> Duration.ZERO);

 // Dispose of the disposable to cancel the operation.
 Disposable disposable = transactionContext.flatMap(transaction -> {
     // Process messages and associate operations with the transaction.
     Mono<Void> operations = Mono.when(
         asyncReceiver.receiveDeferredMessage(sequenceNumber).flatMap(message ->
             asyncReceiver.complete(message, new CompleteOptions().setTransactionContext(transaction))),
         asyncReceiver.abandon(receivedMessage, new AbandonOptions().setTransactionContext(transaction)));

     // Finally, either commit or rollback the transaction once all the operations are associated with it.
     return operations.then(asyncReceiver.commitTransaction(transaction));
 }).subscribe(unused -> {
 }, error -> {
     System.err.println("Error occurred processing transaction: " + error);
 }, () -> {
     System.out.println("Completed transaction");
 });

メソッドの概要

修飾子と型 メソッドと説明
ByteBuffer getTransactionId()

トランザクション ID を取得します。

メソッドの継承元: java.lang.Object

メソッドの詳細

getTransactionId

public ByteBuffer getTransactionId()

トランザクション ID を取得します。

Returns:

トランザクション ID

適用対象