最新使用微服务feign进行服务调用时,出现了如下错误:

 test-test-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

具体的表现是,当 使用feign调用马上就报错,也没有超过设置的超时时间,我的配置如下:

ribbon:
  OkToRetryOnAllOperations: false #对所有操作请求都进行重试,默认false
  ReadTimeout: 60000   #负载均衡超时时间,默认值5000
  ConnectTimeout: 3000 #ribbon请求连接的超时时间,默认值2000
  MaxAutoRetries: 0     #对当前实例的重试次数,默认0
  MaxAutoRetriesNextServer: 1 #对切换实例的重试次数,默认1

hystrix:
  command:
    default:  #default全局有效,service id指定应用有效
      execution:
        timeout:
          #如果enabled设置为false,则请求超时交给ribbon控制,为true,则超时作为熔断根据
          enabled: true
        isolation:
          thread:
            timeoutInMilliseconds: 60000 #断路器超时时间,默认1000ms

例如我设置的ribbon超时时间为60秒,但调用1秒内就报错,一开始怀疑是错误次数太多导致熔断,还设置了熔断窗口和熔断次数,后来发现,hystrix的timeoutInMilliseconds应该配置得比ribbon的大,这样ribbon才会触发超时重试机制,将timeoutInMilliseconds设置成70000就可以了。此外说一点关于hystrix和ribbon的两个关于超时的设置,在feign调用过程中是数值较小的生效。如果各位网友遇到的问题不是我的这个解决方案,由于feign默认输出的日志十分有限,就需要展示更多日志来排查问题,可以加上以下配置,将feign的调用日志详细的展示出来,帮助我们排查,这里我增加了一个配置类:

@Configuration
public class FeignConfig {


    /**
     * 配置请求重试
     * 
     */
    @Bean
    public Retryer feignRetryer() {
        return new Retryer.Default(200, SECONDS.toMillis(2), 10);
    }


    /**
     * 设置请求超时时间
     *默认
         * public Options() {
         * this(10 * 1000, 60 * 1000);
         * }
     *
     */
    @Bean
    Request.Options feignOptions() {
        return new Request.Options(60 * 1000, 60 * 1000);
    }



    /**
     * 打印请求日志
     * @return
     */
    @Bean
    public feign.Logger.Level multipartLoggerLevel() {
        return feign.Logger.Level.FULL;
    }

}

控制台打印出来的日志就像下面所示:

2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] <--- HTTP/1.1 500  (607ms)
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] cache-control: no-cache, no-store, max-age=0, must-revalidate
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] connection: close
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] content-type: application/json;charset=UTF-8
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] date: Mon, 09 Oct 2017 11:31:07 GMT
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] expires: 0
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] pragma: no-cache
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] transfer-encoding: chunked
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] x-application-context: test-test-service:dev:8771
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] x-content-type-options: nosniff
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] x-frame-options: DENY
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] x-xss-protection: 1; mode=block
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] 
2017-10-09 19:31:02.049 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload]


 {
  "code" : 500,
  "error" : "Internal Server Error",
  "data" : null
}



2017-10-09 19:31:02.049 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] <--- END HTTP (72-byte body)

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐