2

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:

  • According this to I set execution isolation strategy to THREAD to avoid time-out:

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

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

  • There seems to be a hint for solution on github by writing a custom RibbonCommand and overriding getFallback(), but after looking at RibbonCommand interface. I found out, that neither RibbonCommand nor its super interfaces doesn't define such a method.

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
4

1 回答 1

1

最新版本支持 Zuul 级别的回退。它是通过扩展 ZuulFallbackProvider 来完成的。请访问以下链接以获取示例: https ://github.com/spring-cloud-samples/zuul-server/blob/master/src/main/java/zuulserver/ZuulServerApplication.java

对于某些类型的路由配置(例如,如果您有基于 url 的配置),不会触发回退触发本身

“这些简单的 url 路由不会作为 HystrixCommand 执行,也不能使用 Ribbon 对多个 URL 进行负载平衡。”

于 2016-11-16T01:34:10.347 回答