for rest api call you can implement the retry mechanism on the client level where actual rest call going
@Retryable(value = Exception.class, maxAttemptsExpression = "${retry.maxAttempts}", backoff = @Backoff(delayExpression = "${retry.maxDelay}"))
public Optional<T> getApiCall(String url, String token, Class<T> resClass) {
ResponseEntity<T> response = null;
try {
logger.info(url);
// create headers
HttpHeaders headers = new HttpHeaders();
// set `accept` header
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setBearerAuth(token);
// set custom header
// headers.set("x-request-src", "desktop");
// build the request
HttpEntity<String> entity = new HttpEntity<>("", headers);
// use exchange method for HTTP call
try {
response = this.restTemplate.exchange(url, HttpMethod.GET, entity, resClass, 1);
} catch (HttpStatusCodeException e) {
return errorService.throwException(HttpStatus.NOT_FOUND, EKDError.LIFPRO406);
}
if (response.getStatusCode() == HttpStatus.OK) {
return Optional.ofNullable(response.getBody());
} else {
return errorService.throwException(HttpStatus.NOT_FOUND, EKDError.LIFPRO406);
}
} catch (HttpClientErrorException | HttpServerErrorException e) {
logger.error("Exception in api call : ", e);
return errorService.throwException(HttpStatus.INTERNAL_SERVER_ERROR, EKDError.LIFPRO407);
}
}
now max attempts and delay is configurable set application.properties maxAttemptsExpression = "${retry.maxAttempts}", backoff = @Backoff(delayExpression = "${retry.maxDelay}"