【发布时间】:2016-10-11 10:18:56
【问题描述】:
我是 Spring Cloud Netflix 的新手,对此有一些疑问。
我将 API 网关与在 Zuul 边缘服务器上运行的 Hystrix 一起使用,我想确保我是否正确理解以下行为:
我杀死了一个在 API 网关“后面”运行的微服务,然后我强制 hystrix 打开电路。之后(大约 10 秒)我向未运行的微服务发送请求并收到 TIMEOUT 错误。但是,当我在很短的时间内(最多 1 秒)发送许多(数十个)请求时,我收到 SHORTCIRCUIT OPEN 错误。
我很惊讶为什么我收到 TIMEOUT 错误,尽管电路是打开的,因此应该使用 hystrix 来避免此类故障。但我猜原因是,如果自上次请求以来的时间 > circuitBreaker.sleepWindowInMilliseconds,那么 API 网关会尝试再次连接到微服务以检查它是否还活着,但它不是,因此 - > TIMEOUT。这也可以解释为什么我在短时间内收到许多请求的 SHORTCIRCUIT OPEN 错误。
接下来我收到“TIMEOUT”或“SHORTCIRCUIT”错误:
HystrixRuntimeException: Microservice (timed-out | short-circuited) and no fallback available
如何在 zuul 服务器上指定一个回退(这对于所有路由都可以相同)以避免此异常?
我到目前为止所尝试的:
-
根据this,我将执行隔离策略设置为线程 避免超时:
hystrix: command.default.execution.isolation.strategy:线程
但是在查看了 hystrix.stream 之后我得到了propertyValue_executionIsolationStrategy":"SEMAPHORE"
- 似乎通过编写自定义 RibbonCommand 并覆盖 getFallback() 来解决 github 的提示,但在查看 RibbonCommand 接口之后。我发现,RibbonCommand 和它的超接口都没有定义这样的方法。
我的 API 网关服务:
@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
【问题讨论】:
标签: java spring netflix-zuul hystrix spring-cloud-netflix