赞
踩
场景:
微服务模块之间互相调用,可能控制台会报请求超时的错误:
错误1:
Read timed out executing POST xxx
错误2:
- com.netflix.hystrix.exception.HystrixTimeoutException: null
- at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:1142) [hystrix-core-1.5.18.jar:1.5.18]
- at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41) [hystrix-core-1.5.18.jar:1.5.18]
- at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37) [hystrix-core-1.5.18.jar:1.5.18]
- at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57) [hystrix-core-1.5.18.jar:1.5.18]
- at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.tick(AbstractCommand.java:1159) [hystrix-core-1.5.18.jar:1.5.18]
- at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:99) [hystrix-core-1.5.18.jar:1.5.18]
- at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_261]
- at java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:308) [na:1.8.0_261]
- at java.util.concurrent.FutureTask.runAndReset(FutureTask.java) [na:1.8.0_261]
- at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_261]
- at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_261]
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_261]
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_261]
- at java.lang.Thread.run(Thread.java:748) [na:1.8.0_261]
-
- 2023-03-04 13:47:43.656 ERROR 1272 --- [ HystrixTimer-2] c.j.a.api.fallback.AccountFeignFallBack : AccountFeign---->消费出现异常:{0}
分析:
1、因为 OpenFeign 的默认请求连接时间仅有几秒钟,需要把请求时间配置的更长一些
2、启动 feign.hystrix 导致配置的 feign.client 超时时间失效
解决:
1、设置 feign.client 的超时时间设置久一点
2、需要禁用 feign.hystrix.enabled=false(暂不知为何,禁用hystrix就行了)。否则启用 hystrix 会导致配置的 feign.client 超时时间失效
3、在 yml 中配置如下代码:
- # 配置 feign 默认请求时间仅几秒钟,配置请求时间长一些(毫秒)
- feign:
- client:
- config:
- default:
- connectTimeout: 600000
- readTimeout: 600000
- hystrix:
- enabled: false # 不要开启hystrix,会导致超时配置不生效
或者
- # 配置 feign 默认请求时间仅几秒钟,配置请求时间长一些(毫秒)
- ribbon:
- ReadTimeout: 60000
- ConnectTimeout: 60000
注意:
1、在服务调用方的yml文件中配置才会生效
2、不要启动 feign.hystrix
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。