I am trying to create few services with spring-boot (1.5.1) using Ribbon + Feign + Hystrix (and my service discovery is spring-boot-zookeeper) and I don't use Zuul.
I was (naive) thinking it should work in following way:
Calling Feign method (annotated by @FeignClient
) - it converts it to some HTTP request which is load balanced in some way by Ribbon, so if sending request fails, it tries (according to ribbon config, i.e. myservice.ribbon.MaxAutoRetriesNextServer=2
) to retry on next service of same type/name and finally if all retries fail - it calls Hystrix fallback method.
So my Feign interface
@FeignClient(value = "myservice", fallbackFactory = HystrixMyServiceFallbackFactory.class)
@RibbonClient(name = "myservice")
public interface MyServiceClient {
@RequestMapping(value = "/foo", method = RequestMethod.POST)
Response foo(Object data);
}
Defined Hystrix FallbackFactory to return some default response
public class HystrixMyServiceFallbackFactory implements FallbackFactory<MyServiceClient > {
@Override
public MyServiceClient create(final Throwable throwable) {
return new MyServiceClient () {
@Override
public Response foo(Object data) {
return new Response(-1, "Failed");
}
};
}
}
Somewhere in my code I have following lines:
@Autowired
private MyServiceClient myServiceClient;
public Response doSomething() {
return myServiceClient.foo(new Object());
}
When all services is up (I have 2 of MyService), Ribbon works fine with nice Round Robbin, but when I shut down one of MyService instances, Ribbon continue with Round Robbin, so every second attempt, I receive result of Hystrix Fallback, instead of expected success (ribbon should retry on other service, shouldn't it?), until ribbon server list is updated.
Anybody could explain how it works all this together?