ServiceBusTransactionContext Class
- java.
lang. Object - com.
azure. messaging. servicebus. ServiceBusTransactionContext
- com.
public final class ServiceBusTransactionContext
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 = 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");
});
Method Summary
Modifier and Type | Method and Description |
---|---|
Byte |
getTransactionId()
Gets the transaction id. |
Methods inherited from java.lang.Object
Method Details
getTransactionId
public ByteBuffer getTransactionId()
Gets the transaction id.
Returns:
transaction ID
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
Azure SDK for Java