Spring Reactive Repository: findById(ID) vs. findById(Publisher<ID>)

Viewed 454

What ist better to create a fully non-blocking REST-Service?

Mono<T> findById(ID id);

or

Mono<T> findById(Publisher<ID> id);

Is the second method less blocking?

Here is an example:

@GetMapping
public Mono<UserProfile> getUserProfile(Mono<Authentication> authentication) {
     return reactiveUserProfileRepository.findById(
          authentication.map(auth -> auth.getName()));
}

Or is it good enough to use an object as parameter?

public Mono<UserProfile> getUserProfile(Authentication authentication) {
...
1 Answers

According to the documentation you can benefit from non-blocking reading when using @RequestBody and reactive types:

Unlike Spring MVC, in WebFlux, the @RequestBody method argument supports reactive types and fully non-blocking reading and (client-to-server) streaming.

Related