FilipR
FilipR

Reputation: 1238

Fallback methods at Zuul server in Spring cloud

I am new in Spring Cloud Netflix and have some questions concerning it.
I am using the API Gateway together with Hystrix running at Zuul edge server and I would like to make sure if I understand the following behavior correctly:

I kill a microservice running "behind" API Gateway then I force hystrix to open the circuit. After that (ca 10 seconds) I send a request to the non-running microservice and receive TIMEOUT error. However when I send many (tens) of requests in a very short time (up to 1 sec), I receive SHORTCIRCUIT OPEN error.
I was surprised why I receive TIMEOUT error although the circuit is open and therefore hystrix should come to play to avoid such kind of failures. But I guess the reason is that if time since last request > circuitBreaker.sleepWindowInMilliseconds, then the API Gateway tries to connect to the microservice again to check if it's alive, but it wasn't, thus -> TIMEOUT. That would also explain, why I got SHORTCIRCUIT OPEN error on many requests in short time.

The next thing is that as I receive "TIMEOUT" or "SHORTCIRCUIT" error I got:

HystrixRuntimeException: Microservice (timed-out | short-circuited) and no fallback available

How can I specify a fallback at zuul server (this can be the same for all routes) to avoid this exception ?
What I have tried until now:

but after looking at the hystrix.stream I got propertyValue_executionIsolationStrategy":"SEMAPHORE"

My API Gateway service:

@SpringBootApplication
@EnableSidecar // This annotation includes @EnableCircuitBreaker, @EnableDiscoveryClient, and @EnableZuulProxy
@EnableHystrixDashboard
public class ApiGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiGatewayApplication.class, args);
    }

}

application.yml

server:
  port: 10000
sidecar:
  port: 8000
endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
zuul:
  routes:
    microservice:
      path: /microservice/**

hystrix:
  command.default.execution.isolation.strategy: THREAD

debug: true

Upvotes: 2

Views: 5536

Answers (1)

vasanth
vasanth

Reputation: 81

The latest release supports fallback at Zuul level. It is done by extending the ZuulFallbackProvider. Please visit the below link for an example: https://github.com/spring-cloud-samples/zuul-server/blob/master/src/main/java/zuulserver/ZuulServerApplication.java

The fallback triggering itself is not done for certain types of route configurations (for eg if you have a url based config)

"These simple url-routes don’t get executed as a HystrixCommand nor can you loadbalance multiple URLs with Ribbon."

Upvotes: 1

Related Questions