2017-06-20 60 views
0

我有一个Spring Boot Zuul作为外部网关和Eureka作为服务发现的场景,所有这些都在Kubernetes中运行。Zuul重试配置不适用于Eureka

事情是,我想保证我的服务的可用性,所以当我的服务实例出现故障时,我希望Zuul通过Eureka重新尝试调用其他实例之一。

我试着按照这样做Ryan Baxter's post。 另外,我试图按照here的提示进行操作。

问题是,无论我做什么,看起来像Zuul不会重试打电话。当我删除我的一个实例时,它会一直向我返回此实例的超时,直到Eureka地址得到同步。

我application.yaml看起来是这样的:

spring: 
    cloud: 
    loadbalancer: 
     retry: 
     enabled: true 

zuul: 
    stripPrefix: true 
    ignoredServices: '*' 
    routes: 
    my-service: 
     path: /my-service/** 
     serviceId: my-service-api 
    retryable: true 

my-service: 
    ribbon: 
    maxAutoRetries: 3 
    MaxAutoRetriesNextServer: 3 
    OkToRetryOnAllOperations: true 
    ReadTimeout: 5000 
    ConnectTimeout: 3000 

我的服务是使用卡姆登SR7(我也试过SR6):

"org.springframework.cloud:spring-cloud-dependencies:Camden.SR7" 

而且还弹簧重试:

org.springframework.retry:spring-retry:1.1.5.RELEASE 

我的应用程序类看起来像这样:

@SpringBootApplication 
@EnableEurekaClient 
@EnableZuulProxy 
@EnableRetry 
public class MyZuulApplication 

编辑:

制作打通邮差,它带来

{ 
    "timestamp": 1497959364819, 
    "status": 500, 
    "error": "Internal Server Error", 
    "exception": "com.netflix.zuul.exception.ZuulException", 
    "message": "TIMEOUT" 
}. 

以一看Zuul日志,它印{"level":"WARN","logger_name":"org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter","appName":...,"message":"Error during filtering","stack_trace":"com.netflix.zuul.exception.ZuulException: Forwarding error [... Stack Trace ...] Caused by: com.netflix.hystrix.exception.HystrixRuntimeException: my-service-api timed-out and no fallback available [... Stack Trace ...] Caused by: java.util.concurrent.TimeoutException: null

另一个有趣的日志,我发现:

{"level":"INFO" [...] current list of Servers=[ip_address1:port, ip_address2:port, ip_address3:port],Load balancer stats=Zone stats: {defaultzone=[Zone:[ ... ]; Instance count:3; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;] 
},Server stats: [[Server:ip_address1:port; [ ... ] Total Requests:0; Successive connection failure:0; Total blackout seconds:0; [ ... ] 
, [Server:ip_address2:port; [ ... ] Total Requests:0; Successive connection failure:0; Total blackout seconds:0; [ ... ] 
, [Server:ip_address3:port; [ ... ] Total Requests:0; Successive connection failure:0; Total blackout seconds:0; [ ... ] 
+0

你得到了什么确切的例外? –

+0

我编辑原始文章的一些更多的信息 –

回答

0

该问题似乎是由Hystrix造成的时间到。 HystrixCommand的默认超时时间为1000毫秒,对于功能区重试http请求是不够的。 尝试增加hystrix的超时时间,如下所示。

hystrix: 
    command: 
    default: 
     execution: 
     isolation: 
      thread: 
      timeoutInMilliseconds: 20000 

这将增加整个椎命令的超时时间为20秒。如果有效,请为您的环境调整以上值。您正在使用相当大的超时值进行读取和连接超时。因此,如果需要,您需要使用hystrix超时调整这些值。

+0

感谢您的帮助。我会稍后再尝试,然后在这里发帖。 –

+0

我测试过它,它像一个魅力。我会将超时调整为对我更有意义的事情。谢谢! –

相关问题