当前位置:   article > 正文

SpringCloud使用@FeignClient服务之间调用,报超时异常解决_com.netflix.hystrix.exception.hystrixtimeoutexcept

com.netflix.hystrix.exception.hystrixtimeoutexception: null

场景:

微服务模块之间互相调用,可能控制台会报请求超时的错误:

错误1:

Read timed out executing POST xxx

错误2:

  1. com.netflix.hystrix.exception.HystrixTimeoutException: null
  2. at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:1142) [hystrix-core-1.5.18.jar:1.5.18]
  3. at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41) [hystrix-core-1.5.18.jar:1.5.18]
  4. at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37) [hystrix-core-1.5.18.jar:1.5.18]
  5. at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57) [hystrix-core-1.5.18.jar:1.5.18]
  6. at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.tick(AbstractCommand.java:1159) [hystrix-core-1.5.18.jar:1.5.18]
  7. at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:99) [hystrix-core-1.5.18.jar:1.5.18]
  8. at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_261]
  9. at java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:308) [na:1.8.0_261]
  10. at java.util.concurrent.FutureTask.runAndReset(FutureTask.java) [na:1.8.0_261]
  11. at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_261]
  12. at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_261]
  13. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_261]
  14. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_261]
  15. at java.lang.Thread.run(Thread.java:748) [na:1.8.0_261]
  16. 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 中配置如下代码:

  1. # 配置 feign 默认请求时间仅几秒钟,配置请求时间长一些(毫秒)
  2. feign:
  3. client:
  4. config:
  5. default:
  6. connectTimeout: 600000
  7. readTimeout: 600000
  8. hystrix:
  9. enabled: false # 不要开启hystrix,会导致超时配置不生效

或者

  1. # 配置 feign 默认请求时间仅几秒钟,配置请求时间长一些(毫秒)
  2. ribbon:
  3. ReadTimeout: 60000
  4. ConnectTimeout: 60000

注意:
1、在服务调用方的yml文件中配置才会生效
2、不要启动 feign.hystrix

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/84674
推荐阅读
相关标签
  

闽ICP备14008679号