我是Spring Cloud Netflix中的新成员,并且有一些与此有关的问题。
我现在用的是API网关一起运行在Zuul边缘服务器豪猪,我想,以确保如果我理解正确的以下行为:Spring云中Zuul服务器的后备方法
我杀了运行“后面”微服务API网关然后我强迫椎到打开电路。之后(大约10秒),我向非运行的微服务发送请求并收到TIMEOUT错误。但是,当我在很短的时间内(最多1秒)发送很多(几十个)请求时,我收到SHORTCIRCUIT OPEN错误。
我很惊讶,为什么我收到TIMEOUT错误,虽然电路是开放的,因此hystrix应该发挥作用,以避免这种类型的故障。但我想原因是,如果自上次请求以来的时间> circuitBreaker.sleepWindowInMilliseconds,那么API网关会尝试再次连接到微服务以检查它是否存在,但它不是,因此 - > TIMEOUT。这也可以解释为什么我在短时间内在很多请求中出现SHORTCIRCUIT OPEN错误。
接下来的事情是,当我收到“超时”或“短路”的错误我:
HystrixRuntimeException: Microservice (timed-out | short-circuited) and no fallback available
我怎么能指定在zuul服务器回退(这可能是所有路由相同),以避免这种异常?
我已经试过至今:
据this到我设置执行隔离策略主题 避免超时:
椎: command.default.execution.isolation.strategy:螺纹
但看hystrix.stream后,我得到了propertyValue_executionIsolationStrategy":"SEMAPHORE"
- 通过编写自定义RibbonCommand和覆盖getFallback(),但在看到RibbonCommand接口后,似乎有提示解决方案github。我发现,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
您应该考虑提供一个版本号来帮助引导用户解决他们的问题的正确版本 – scicalculator
在官方的spring文档中我错过了多少东西,这是惊人的。无法弄清楚为什么我的回退方法没有被称为失败的url路由。 +1 – Bal