I'm facing an issue with WebClient
and reactor-extra
. Indeed, I have the following method :
public Employee getEmployee(String employeeId) {
return webClient.get()
.uri(FIND_EMPLOYEE_BY_ID_URL, employeeId)
.retrieve()
.onStatus(HttpStatus.NOT_FOUND::equals, clientResponse -> Mono.empty())
.onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new MyCustomException("Something went wrong calling getEmployeeById")))
.bodyToMono(Employee.class)
.retryWhen(Retry.onlyIf(ConnectTimeoutException.class)
.fixedBackoff(Duration.ofSeconds(10))
.retryMax(3))
.block();
}
I've found that I could use retryWhen(Retry.onlyIf(...))
because I want to retry only if a ConnectTimeoutException
is thrown. I've found this solution from this post : spring webclient: retry with backoff on specific error
But, in the latest version of reactor
the following method became deprecated :
public final Mono<T> retryWhen(Function<Flux<Throwable>, ? extends Publisher<?>> whenFactory)
After hours of googling I haven't found any solution to this question : Is there any alternative for retryWhen
and Retry.onlyIf
with the latest versions of reactor
Thanks for your help !