Is it possible to have transaction management using Spring Webflux? We will be building a microservice and I'm considering using Spring Webflux but I'd like to make sure that a PUT/POST request that mutates state can be atomic. For example if the request that is received needs to:
Is it possible to wrap the steps within a Transaction so that the changes are atomic?
Nested transactions in Spring are just JDBC / database savepoints. If you don't know what a savepoint is, have a look at this tutorial, for example. Note that savepoint support is dependent on your JDBC driver/database.
ChainedTransactionManager (Deprecated) ChainedTransactionManager is a way of declaring multiple data sources, in which, in the case of exception, rollbacks will occur in the reverse order. Thus, with three data sources, if an error occurred during a commit on the second, only the first two will try to roll back.
Spring WebFlux internally uses Project Reactor and its publisher implementations, Flux and Mono. The new framework supports two programming models: Annotation-based reactive components. Functional routing and handling.
You can use TransactionTemplate
in your reactive code:
private TransactionTemplate transactionTemplate;
// save to DB method
public Void saveMembers(Member m1, Member m2) {
saveMember(m1);
saveMember(m2);
}
// your reactive method
public Mono<Void> saveMembersAsync(Member m1, Member m) {
return Mono.fromCallable(() -> transactionTemplate.execute(transactionStatus ->
saveMembers(m1, m2)));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With