【发布时间】:2023-03-20 00:23:02
【问题描述】:
我遇到了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)
经过数小时的谷歌搜索,我还没有找到任何解决这个问题的方法:retryWhen 和 Retry.onlyIf 有没有最新版本的reactor 的替代品
感谢您的帮助!
【问题讨论】:
标签: spring-boot reactive-programming project-reactor spring-webclient reactor-netty