我正在从 feign 客户端切换到响应式 feign 客户端,我为 feign 定义了全局重试器:
@Bean
Retryer retryer() {
return new Retryer.Default(100, 1, 5);
}
@Bean
ErrorDecoder errorDecoder() {
return new HttpErrorDecoder();
}
static class HttpErrorDecoder implements ErrorDecoder {
private final ErrorDecoder defaultErrorDecoder = new Default();
@Override
public Exception decode(String methodKey, Response response) {
Exception exception = defaultErrorDecoder.decode(methodKey, response);
if (response.status() != HttpStatus.SC_OK) {
return new RetryableException(response.status(),
"api call for url: " + response.request().url() + " failed",
response.request().httpMethod(), exception.getCause(), null,
response.request());
}
return exception;
}
}
使用非反应式客户端重试工作正常,使用反应式客户端错误解码器会引发 RetryableException,但 Retryer 没有反应 - 不执行重试。我主要使用 webflux Mono<T>
,有没有办法让它工作,或者 Retryer 不能用于响应式假装?如果是这样,是否可以定义“全局重试”或者我是否需要为每个呼叫/单声道定义重试?