Hystrix、Ribbon、openfeign的超时时间配置

说明

因为openfeign的请求是:Hystrix+Ribbon。

Hystrix在最外层,然后再到Ribbon,最后里面的是http请求。

所以,Hystrix的熔断时间必须大于Ribbon的 ( ConnectTimeout + ReadTimeout )。

而如果Ribbon 开启了重试机制,还需要乘以对应的重试次数,保证在Ribbon里的请求还没结束时,Hystrix的熔断时间不会超时。

服务调用者

开启Feign的hystrix开关

feign:
  hystrix:
    enabled: true

配置 ribbon 超时时长

ribbon:
  ReadTimeout: 4000   #超时时间,默认值5000
  ConnectTimeout: 3000 #ribbon请求连接的超时时间,默认值2000

配置 hystrix 超时时长

hystrix:
  command:
    default:
      execution:
        timeout:
          enable: true #为false则超时控制有ribbon控制,为true则hystrix超时和ribbon超时都用,但是谁小谁生效,默认为true,即:hystrix超时会引发降级
        isolation:
          thread:
            timeoutInMilliseconds: 10000 #hystrix的超时时长默认1秒,时间太短,业务还没完成就超时降级了

注意:关于hystrix在application配置文件中没提示,但是HystrixCommandProperties是会获取的。

感谢:
https://www.cnblogs.com/Howinfun/p/12149982.html

https://www.cnblogs.com/qingmuchuanqi48/p/13138428.html