I'm beginning a foray into the world of reactive Java programming using Webflux in Spring Boot.
I'm running into a scenario where it's really hard to do a certain database call reactively.
If I do a single blocking database call within a Mono, what happens?
The code would look something like this...
public Mono<ReturnThing> isThisAsyncOrNot() {
//Async, non-blocking API call
return webClient.doSomeAPIWork()
.flatMap(whatevers -> {
//Synchronous, blocking database call
ReturnThing returnThing= returnThingRepo.getByWhateverId(whatever.ID);
}
return returnThing;
});
}
Now yes, I know that there's an easy way to do this reactively. That's not the question I'm asking (in fact, the real code is quite a bit more complex).
What I really want to know is what that synchronous database call will do to my performance. Will the overall method still be async non-blocking (except during the part where the db call is made, which is blocking)? Or will this somehow ruin the whole reactive paradigm and cause the entire thing, start to finish, to be blocking?
flatMap()
returnsReturnThing
and notMono
. I understand that you wanted to simplify your code, but now there is a confusion. Does yourgetByWhateverId()
method returnMono
(but in that case it is reactive), or did you meanmap()
instead offlatMap()
? – Daggett