I have the following code where if I keep the retry annotation on the controller method, then it is getting retried but if I keep the retry annotation on a different method, it doesn't retry. Scenario is, in the API method, createOrder(), I fetch the orderId from an external system which is working fine. But I need to retry the createOrder(String orderId) method which fails some of the times.
@GetMapping("/order")
//@Retry(name = ORDERSERVICE, fallbackMethod = "fallback_retry")
public ResponseEntity<String> createOrder() {
int orderId = 1; // makeDBCall or fetch it from somewhere
return createOrder(orderId); // need to retry this method in case it fails
}
@Retry(name = ORDERSERVICE, fallbackMethod = "fallback_retry")
public ResponseEntity<String> createOrder(int orderId) {
logger.info("item service call attempted:::" + attempts++);
String response = restTemplate.getForObject("http://localhost:8081/item/" + orderId, String.class);
logger.info("item service called");
return new ResponseEntity<String>(response, HttpStatus.OK);
}
resilience4j.retry:
instances:
orderService:
maxRetryAttempts: 3
waitDuration: 11000