Spring / Spring Retry Interview Questions
Can Spring Retry be used with Spring Cloud OpenFeign? How?
Yes, Spring Retry integrates with Spring Cloud OpenFeign to add retry capability to Feign client calls. When Spring Retry is on the classpath and spring.cloud.openfeign.okhttp.enabled or Feign defaults are in use, you can configure retry through Feign's own Retryer mechanism or delegate to Spring Retry's RetryTemplate.
Approach 1 — Feign native Retryer bean:
@Bean public Retryer feignRetryer() { return new Retryer.Default( 100, // period (ms) 1000, // maxPeriod (ms) 3 // maxAttempts ); }
Approach 2 — Wrapping the Feign interface with @Retryable:
@Service public class OrderService { @Autowired private OrderFeignClient feignClient; @Retryable(retryFor = FeignException.ServiceUnavailable.class, maxAttempts = 3) public OrderDto getOrder(Long id) { return feignClient.getOrder(id); } }
The second approach is more flexible because you can mix @Recover and backoff strategies from Spring Retry while Feign handles HTTP communication. Note: Feign's built-in Retryer and Spring Retry should not both be active for the same operation to avoid double-retry issues. Disable the default Feign retryer (Retryer.NEVER_RETRY) if using Spring Retry.
More Related questions...