当实例关闭时,Spring-cloud Zuul重试

时间:2016-03-02 15:36:12

标签: spring spring-cloud microservices netflix-eureka netflix-zuul

使用Spring-cloud Angel.SR6:

以下是使用@EnableZuulProxy的我的Spring-boot应用程序的配置:

java.lang.NullPointerException
    at GroundTruthMarker$3.mouseClicked(GroundTruthMarker.java:101)
    at java.awt.Component.processMouseEvent(Component.java:6538)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

我有2个server.port=8765 ribbon.ConnectTimeout=500 ribbon.ReadTimeout=5000 ribbon.MaxAutoRetries=1 ribbon.MaxAutoRetriesNextServer=1 ribbon.OkToRetryOnAllOperations=true zuul.routes.service-id.retryable=true 个实例在随机端口上运行。这些实例以及Zuul实例成功注册了Eureka,我可以通过访问http://localhost:8765/service-id/来访问2 service-id个实例上的RESTful端点,并发现它们在一轮中是平衡的-robin方式。

我想杀死其中一个service-id个实例,当这个已解散的实例接下来要转发时,让Zuul尝试联系它,失败并重试另一个实例。

这可能,或者我误读了文档?当我尝试上面的配置时,针对已解散实例的'destined'请求失败,并出现500 Forwarding错误。来自Zuul stacktrace:

service-id

后续请求按预期成功。此行为将继续,直到从Zuul的注册表中删除已解散的实例。

编辑:已更新至Brixton.M5。行为没有变化。以下是更详细的Hystrix异常:

com.netflix.zuul.exception.ZuulException: Forwarding error
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:140)

....

Caused by: com.netflix.hystrix.exception.HystrixRuntimeException: service-idRibbonCommand timed-out and no fallback available

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。这解决了我的问题:

关于this article功能区仅在http客户端设置为功能区的restclient时才会重新启动。在默认功能区上使用的是Apache http客户端,它不会重试任何请求。

由于功能区的restclient已被弃用,您应该考虑使用spring-retry(https://github.com/spring-projects/spring-retry

请记住,在功能区上配置重试时,您还必须处理zuul的hystrix超时。

答案 1 :(得分:0)

功能区使用eureka中注册的服务,因此eureka可以更新服务状态,让调用者知道可用的服务器。

根据我的理解,当一台服务器停机时,有两种方法可以知道:
1.等待eureka服务器更新服务状态。但是此更新将需要一些时间,默认为30秒 2.尝试拨打电话并将其标记为关闭,(稍后可能会与eureka服务器确认)

所以,在你的问题中,你说在第一次请求失败后,后续请求成功。我认为这是正确的行为。