Interface TransactionalOperator
The central method is transactional(reactor.core.publisher.Flux<T>)
, supporting transactional wrapping
of functional sequences code that. This operator handles the transaction lifecycle
and possible exceptions such that neither the ReactiveTransactionCallback
implementation nor the calling code needs to explicitly handle transactions.
Typical usage: Allows for writing low-level data access objects that use resources such as database connections but are not transaction-aware themselves. Instead, they can implicitly participate in transactions handled by higher-level application services utilizing this class, making calls to the low-level services via an inner-class callback object.
Note: Transactional Publishers should avoid Subscription cancellation. See the Cancel Signals section of the Spring Framework reference for more details.
- Since:
- 5.2
- Author:
- Mark Paluch, Juergen Hoeller
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic TransactionalOperator
create
(ReactiveTransactionManager transactionManager) Create a newTransactionalOperator
usingReactiveTransactionManager
, using a default transaction.static TransactionalOperator
create
(ReactiveTransactionManager transactionManager, TransactionDefinition transactionDefinition) <T> reactor.core.publisher.Flux<T>
execute
(TransactionCallback<T> action) Execute the action specified by the given callback object within a transaction.default <T> reactor.core.publisher.Flux<T>
transactional
(reactor.core.publisher.Flux<T> flux) Wrap the functional sequence specified by the given Flux within a transaction.<T> reactor.core.publisher.Mono<T>
transactional
(reactor.core.publisher.Mono<T> mono) Wrap the functional sequence specified by the given Mono within a transaction.
-
Method Details
-
transactional
default <T> reactor.core.publisher.Flux<T> transactional(reactor.core.publisher.Flux<T> flux) Wrap the functional sequence specified by the given Flux within a transaction.- Parameters:
flux
- the Flux that should be executed within the transaction- Returns:
- a result publisher returned by the callback, or
null
if none - Throws:
TransactionException
- in case of initialization, rollback, or system errorsRuntimeException
- if thrown by the TransactionCallback
-
transactional
<T> reactor.core.publisher.Mono<T> transactional(reactor.core.publisher.Mono<T> mono) Wrap the functional sequence specified by the given Mono within a transaction.- Parameters:
mono
- the Mono that should be executed within the transaction- Returns:
- a result publisher returned by the callback
- Throws:
TransactionException
- in case of initialization, rollback, or system errorsRuntimeException
- if thrown by the TransactionCallback
-
execute
<T> reactor.core.publisher.Flux<T> execute(TransactionCallback<T> action) throws TransactionException Execute the action specified by the given callback object within a transaction.Allows for returning a result object created within the transaction, that is, a domain object or a collection of domain objects. A RuntimeException thrown by the callback is treated as a fatal exception that enforces a rollback. Such an exception gets propagated to the caller of the template.
- Parameters:
action
- the callback object that specifies the transactional action- Returns:
- a result object returned by the callback
- Throws:
TransactionException
- in case of initialization, rollback, or system errorsRuntimeException
- if thrown by the TransactionCallback
-
create
Create a newTransactionalOperator
usingReactiveTransactionManager
, using a default transaction.- Parameters:
transactionManager
- the transaction management strategy to be used- Returns:
- the transactional operator
-
create
static TransactionalOperator create(ReactiveTransactionManager transactionManager, TransactionDefinition transactionDefinition) - Parameters:
transactionManager
- the transaction management strategy to be usedtransactionDefinition
- the transaction definition to apply- Returns:
- the transactional operator
-