【发布时间】:2021-03-17 10:39:46
【问题描述】:
我正在努力理解@Retryable。我需要的是在收到 5xx 异常时重试 3 次,如果重试也失败,则在恢复方法中抛出自定义异常。如果抛出了其他异常,则捕获它并抛出自定义异常。
@Retryable(value = HttpServerErrorException.class, maxAttempts = 3, backoff = @Backoff(delay = 3000))
public String callToService(String key) {
String response;
try {
response = //assume a service call here
}catch (Exception ex) {
throw new customException("some message");
}
return response;
}
@Recover
public void retryFailed(HttpServerErrorException httpServerErrorException) {
throw new customException("some message");
}
【问题讨论】: