I'm struggling with understanding @Retryable. What I need is to retry 3 times when I get 5xx Exception and if retry also fails then throw a custom exception in the recovery method. And if some other exception is thrown then catch it and throw a custom exception.
@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");
}