2017-06-20 116 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

我測試過它,它像一個魅力。我會將超時調整爲對我更有意義的事情。謝謝! –

相關問題