Search code examples
springspring-bootnetflix-eurekanetflix-zuulhystrix

How to handle hystrix fallback in zuul?


I'm beginer to micro-services, so please help me out on this issue,

I'm working on simple micro service project with spring boot, zuul, hystrix and eureka. One of service calls data from another service. But when the service is down, response is 500, so it needs to be send request again to get the expected result.

But end user shouldn't it see. So is there a way to send a http request for the failed service again with zuul if the previous request is failed/short circuited.

Thanks in advance.


Solution

  • First for an unavailable service http code 503 is probably more suitable.

    Then Zuul is an api gateway not a service mesh. I think you mix up both concepts here.

    The goal of an api gateway is to accept traffic from outside your network and distributes it internally...and so abstract his complexity(it is actually a distributed facade/router). Example: zuul, spring cloud gateway

    A Service mesh acts as a proxy between microservices and bring on communications aspects like automatic retries, circuit breaker, tracing, logging.

    Example Istio, Linkerd

    But you can go without service mesh to implement this concern. Your caller microservice can protect itself by implementing timeout, retries and circuit breakers by embed a powerful library like resilience4j.(hystrix is actually at the end of his life)

    This library will provide you an api allowing you to wrap communications with outside (other microservices) through a special proxy that will handle retries or/and circuit breakers for you. You should have a look : https://github.com/resilience4j/resilience4