@Retryable(value = ABCDException.class,
maxAttemptsExpression = 3,
backoff = @Backoff(delayExpression = "#{${application.delay}}"))
public String postABCDrequest(ABCDrequest abcdRequest) throws ABCDException {
try {
return restCalltopostData(abcdRequest);
} catch (AnyException e) {
log.error("Error Occured ", e);
throw new ABCDException("Error Occured ", e);
}
}
In this method, I need to retry posting data only when I get certain response codes. I have searched for a few options which isnt suitable for my solution. Is there any simpler way by using annotation?
In catch block, you won't be able to get hold of the response code. Since you're interested in all
5xx
, put a check forresponse.getStatusCode().is5xxServerError()
and re-throw the exceptionABCDException.class
if the exceptions are well handled at the server end and returns the status code. This way you code will continue to retry for all5xx
exceptions until themaxAttempts
gets exhausted.Else, you can simply retry for
HttpServerErrorException.class
by replacingABCDException.class
.