Since R2DBC is reactive and non blocking I would like to understand the benefit of using R2DBC in a simple RESTful CRUD service
Assume a spring boot application is exposing a RESTful service using a repository below
public interface CustomerRepository extends ReactiveCrudRepository<Customer, Long> {
@Query("SELECT * FROM customer WHERE last_name = :lastname")
Flux<Customer> findByLastName(String lastName);
}
This repository is called from a service and the results needs to be transformed in the service before returning to controller.
Flux<Customer> customers = repository.findAll();
In order to access the complete list of customers , I need to invoke blockLast()
on the Flux which makes it blocking and defeats the purpose of using reactive components
Does that mean that there is no benefit of using R2DBC in this simple example ? Am I missing something ?
Can flux be used only for asynchronous subscription where the processing of Flux collections happens in a different thread ?
> in the above example , apart from the fact that the code can stay in a reactive context ?
– lives Jul 09 '21 at 17:06