【Spring Cloud】使用feign客户端请求服务第一次超时问题

原因

由于使用feign,spring cloud默认整合了Ribbon、Hystrix。而Hystrix默认的超时时间为1s,而使用feign第一次请求在配置较差的机器上运行时,很可能请求时间超过1s而超时。

解决方案

1、设置Hystrix的超时时间,例如设置超时时间为5s

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000

2、不设置Hystrix的超时时间

hystrix.command.default.execution.timeout.enabled: false

3、禁用Hystrix

feign.hystrix.enabled: false

以上三种方式皆是在服务消费端的application.properties或application.yml文件中配制。

猜你喜欢

转载自blog.csdn.net/horse_well/article/details/88855960