2016-06-10 19 views
1

我是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 

回答

1

最新版本支持回退在Zuul水平。这是通过扩展ZuulFallbackProvider完成的。请访问以下链接为例: https://github.com/spring-cloud-samples/zuul-server/blob/master/src/main/java/zuulserver/ZuulServerApplication.java

回退触发本身不是为某些类型的路由配置的实现(对于例如,如果你有一个基于URL配置)

“这些简单的URL的路由唐不会像HystrixCommand那样执行,也不能使用Ribbon对多个URL进行负载平衡。“

+0

您应该考虑提供一个版本号来帮助引导用户解决他们的问题的正确版本 – scicalculator

+0

在官方的spring文档中我错过了多少东西,这是惊人的。无法弄清楚为什么我的回退方法没有被称为失败的url路由。 +1 – Bal

相关问题