I'd like to do the following using the WebClient
from spring webflux:
- Call
endpoint1
- If it fails with an expected error then
- call
endpoint2
and - retry
endpoint1
only once
- call
I've got this far:
webclient.get()
.uri("/endpoint1")
.retrieve()
.bodyToFlux(MyBody.class)
.retry(error -> {
if (error == expectedError) {
webclient.get()
.uri("/endpoint2")
.retrieve().block();
return true;
} else {
false;
});
I cannot block when requesting endpoint2
since I would get the following error: block()/blockFirst()/blockLast() are blocking, which is not supported in thread
(I wouldn't like to block either).
Maybe I should use retryWhen
but I'm not really sure how to use it.