为Zuul路由故障设置默认回退

时间:2016-09-29 17:48:45

标签: spring spring-cloud netflix-zuul hystrix spring-cloud-netflix

我们正在尝试覆盖Zuul边缘服务器中存在路由故障时获得的默认错误页面,并且没有任何运气。我们的路线设置如下:

zuul:
  routes:
    ui: /**
    api: /api/**

默认情况下,SendErrorFilter会尝试将请求发送到/ error,并且当ui服务启动并运行时它将起作用,因为它将提供/错误。但问题是当ui服务器关闭时,它会尝试路由到/ error并失败。然后,您的屏幕上出现了一个非常令人讨厌的异常,说有一个转发错误,没有可用的回退。

com.netflix.zuul.exception.ZuulException: Forwarding error
    org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:140)
    org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:105)
    com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112)
    com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:197)
    com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:161)
    com.netflix.zuul.FilterProcessor.route(FilterProcessor.java:120)
    com.netflix.zuul.ZuulRunner.route(ZuulRunner.java:84)
    com.netflix.zuul.http.ZuulServlet.route(ZuulServlet.java:111)

Root Cause:
    com.netflix.hystrix.exception.HystrixRuntimeException: uiRibbonCommand failed and no fallback available.
    com.netflix.hystrix.AbstractCommand$16.call(AbstractCommand.java:807)
    com.netflix.hystrix.AbstractCommand$16.call(AbstractCommand.java:794)
    rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:77)
    rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70)
    rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70)
    rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70)
    com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1516)
    com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1406)
    com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:314)
    com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:306)

如何在Zuul中设置默认回退来处理这些错误,以便用户不会看到令人讨厌的异常?我已经看到了这个open issue on spring-cloud-netflix (#250),但我会处理所有路由的默认回退,而不仅仅是特定路由。这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

最新版本的Spring云现在支持回退。请查看帖子 - Fallback methods at Zuul server in Spring cloud 了解更多详情