Hystrix supports the notion of a fallback: a default code path that is executed when they circuit is open or there is an error. To enable fallbacks for a given @FeignClient set the fallback attribute to the class name that implements the fallback. You also need to declare your implementation as a Spring bean.
@@ -595,21 +596,21 @@ static class HystrixClientFallback implements HystrixClient {
@FeignClient(name = "hello", fallbackFactory = HystrixClientFallbackFactory.class)
protected interface HystrixClient {
- @RequestMapping(method = RequestMethod.GET, value = "/hello")
- Hello iFailSometimes();
+ @RequestMapping(method = RequestMethod.GET, value = "/hello")
+ Hello iFailSometimes();
}
@Component
static class HystrixClientFallbackFactory implements FallbackFactory<HystrixClient> {
- @Override
- public HystrixClient create(Throwable cause) {
- return new HystrixClient() {
- @Override
- public Hello iFailSometimes() {
- return new Hello("fallback; reason was: " + cause.getMessage());
- }
- };
- }
+ @Override
+ public HystrixClient create(Throwable cause) {
+ return new HystrixClient() {
+ @Override
+ public Hello iFailSometimes() {
+ return new Hello("fallback; reason was: " + cause.getMessage());
+ }
+ };
+ }
}