使用功能区时,拒绝连接无法使用重试

时间:2018-05-31 01:20:19

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

信息:

spring-cloud.version=Dalston.SR5
spring-boot-starter-parent=1.5.7.RELEASE
zuul-core=1.3.0

当一个客户端的状态为down(我的意思是杀死它),但是zuul也可以有实例信息的缓存,所以请求将路由到down客户端,但是没有正确的响应。所以zuul会重试,路由请求到另一个客户端并获得正确的响应。 这种情况就像重新启动我的客户端一样。

所以我有一些配置:

ribbon:
    MaxAutoRetries: 1
    MaxAutoRetriesNextServer: 2
    OkToRetryOnAllOperations: true
    ReadTimeout: 1000
    ConnectTimeout: 250
    ServerListRefreshInterval: 1000
zuul:
  retryable: true

我使用spring-retry jar:

<dependency>
    <groupId>org.springframework.retry</groupId>
    <artifactId>spring-retry</artifactId>
</dependency>

但它不像我想的那样有用。所以我调试代码。 当zuul路由请求时将使用RetryableRibbonLoadBalancingHttpClient

的例外情况
org.springframework.cloud.netflix.ribbon.apache.RetryableRibbonLoadBalancingHttpClient#execute
final HttpResponse httpResponse = RetryableRibbonLoadBalancingHttpClient.this.delegate.execute(httpUriRequest);

我在它之后找到了重试代码,因此无法重试逻辑。 你能给出一些建议来解决这个问题吗? 例外信息:

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 172.16.73.151:8701 [/172.16.73.151] failed: Connection refused
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.3.jar:4.5.3]
    at org.springframework.cloud.netflix.ribbon.apache.RetryableRibbonLoadBalancingHttpClient$1.doWithRetry(RetryableRibbonLoadBalancingHttpClient.java:89) ~[spring-cloud-netflix-core-1.3.6.RELEASE.jar:1.3.6.RELEASE]
    at org.springframework.cloud.netflix.ribbon.apache.RetryableRibbonLoadBalancingHttpClient$1.doWithRetry(RetryableRibbonLoadBalancingHttpClient.java:71) 

1 个答案:

答案 0 :(得分:0)

我建议您添加以下配置并检查它是否有效:

OrderChecked