Class ReactiveTransactions
java.lang.Object
com.couchbase.client.java.transactions.ReactiveTransactions
An asynchronous version of
Transactions
, allowing transactions to be created and run in an asynchronous
manner.
The main method to run transactions is run(java.util.function.Function<com.couchbase.client.java.transactions.ReactiveTransactionAttemptContext, reactor.core.publisher.Mono<?>>, com.couchbase.client.java.transactions.config.TransactionOptions)
.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionrun
(Function<ReactiveTransactionAttemptContext, Mono<?>> transactionLogic) Convenience overload that runsrun(java.util.function.Function<com.couchbase.client.java.transactions.ReactiveTransactionAttemptContext, reactor.core.publisher.Mono<?>>, com.couchbase.client.java.transactions.config.TransactionOptions)
with a defaultPerTransactionConfig
.run
(Function<ReactiveTransactionAttemptContext, Mono<?>> transactionLogic, TransactionOptions options) Runs the supplied transactional logic until success or failure.
-
Constructor Details
-
ReactiveTransactions
-
-
Method Details
-
run
public Mono<TransactionResult> run(Function<ReactiveTransactionAttemptContext, Mono<?>> transactionLogic, @Nullable TransactionOptions options) Runs the supplied transactional logic until success or failure.This is the asynchronous version of
Transactions.run(java.util.function.Consumer<com.couchbase.client.java.transactions.TransactionAttemptContext>, com.couchbase.client.java.transactions.config.TransactionOptions)
, so to cover the differences:- The transaction logic is supplied with a
CoreTransactionAttemptContext
, which contains asynchronous methods to allow it to read, mutate, insert and delete documents. - The transaction logic should run these methods as a Reactor chain - as standard with reactive programming.
- The transaction logic should return a
Mono<Void>
. AnyFlux
orMono
can be converted to aMono<Void>
by calling.then()
on it. - This method returns a
Mono<TransactionResult>
, which should be handled as a normal Reactor Mono.
- Parameters:
transactionLogic
- the application's transaction logicoptions
- the configuration to use for this transaction- Returns:
- there is no need to check the returned
TransactionResult
, as success is implied by the lack of a thrown exception. It contains information useful only for debugging and logging. - Throws:
TransactionFailedException
- or a derived exception if the transaction fails to commit for any reason, possibly after multiple retries. The exception contains further details of the error.
- The transaction logic is supplied with a
-
run
public Mono<TransactionResult> run(Function<ReactiveTransactionAttemptContext, Mono<?>> transactionLogic) Convenience overload that runsrun(java.util.function.Function<com.couchbase.client.java.transactions.ReactiveTransactionAttemptContext, reactor.core.publisher.Mono<?>>, com.couchbase.client.java.transactions.config.TransactionOptions)
with a defaultPerTransactionConfig
.
-