Feign【首次请求失败】

当feign和ribbon整合hystrix之后,可能会出现首次调用失败的问题,出现原因分析如下:

hystrix默认的超时时间是1秒,如果接口请求响应超过这个时间,将会执行fallback,spring在装配bean的机制以及懒加载原因,feign的首次请求都会相对较慢,如果请求超过1秒,就会出现请求失败。

下面介绍3种处理方式:

1、将hystrix的超时时间改为5秒,配置如下:

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000

2、禁用hystrix的超时时间,配置如下:

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

3、使用feign的时候,直接关闭hystrix,不推荐这种方式:

feign.hystrix.enabled=false

针对feign首次请求失败,可以参考:https://github.com/spring-cloud/spring-cloud-netflix/issues/768

原文地址:https://www.cnblogs.com/idoljames/p/11682173.html