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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
