我遇到了一个与 WebClient
和 reactor-extra
相关的问题。事实上,我有以下方法:
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();
}
我发现我可以使用retryWhen(Retry.onlyIf(...))
,因为我希望只在抛出ConnectTimeoutException
时重试。我从这篇帖子中找到了这个解决方案:spring webclient:retry with backoff on specific error
但是,在最新版本的reactor
中,以下方法已被弃用:
public final Mono<T> retryWhen(Function<Flux<Throwable>, ? extends Publisher<?>> whenFactory)
经过几个小时的搜索,我没有找到任何对这个问题的解决方案:是否有任何替代品可以与最新版本的reactor
一起使用retryWhen
和Retry.onlyIf
?
感谢您的帮助!
reactor-core
中,而不是reactor-extra
。 - Michael Berry