Fegion-4解决Fegion第一次请求timeout的问题
生活随笔
收集整理的這篇文章主要介紹了
Fegion-4解决Fegion第一次请求timeout的问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首次訪問會有一個timeout 500的錯誤https://github.com/spring-cloud/spring-cloud-netflix/issues/768java.util.concurrent.TimeoutException: nullat com.netflix.hystrix.AbstractCommand$9.call(AbstractCommand.java:596) ~[hystrix-core-1.4.21.jar:1.4.21]at com.netflix.hystrix.AbstractCommand$9.call(AbstractCommand.java:577) ~[hystrix-core-1.4.21.jar:1.4.21]at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:99) ~[rxjava-1.0.14.jar:1.0.14]at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.14.jar:1.0.14]at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.14.jar:1.0.14]at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:951) ~[hystrix-core-1.4.21.jar:1.4.21]at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41) ~[hystrix-core-1.4.21.jar:1.4.21]at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37) ~[hystrix-core-1.4.21.jar:1.4.21]at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57) ~[hystrix-core-1.4.21.jar:1.4.21]at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.tick(AbstractCommand.java:971) ~[hystrix-core-1.4.21.jar:1.4.21]at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:98) ~[hystrix-core-1.4.21.jar:1.4.21]at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_66]at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[na:1.8.0_66]at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_66]at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[na:1.8.0_66]at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_66]at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_66]at java.lang.Thread.run(Thread.java:745) [na:1.8.0_66]跟我們的異常是一樣的@spencergibb After a bunch more experimentation with a simplified client, I believe everything really is working OK, and the initial request just takes longer than 1 second, which is the default hystrix timeout. I'm guessing some framework related code lazily does certain tasks so the initial request really does just take longer so the timeout is valid. I apologize for the noise. Thanks for the help!7. Declarative REST Client: FeignSpring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.其實它還整合了一個東西是hystrix,它是Feign的一個小東西,由于我們第一次請求的時候超過一秒,所以就報了一個超時的異常Hystrix command fails with "timed-out" and no fallback avaliablehttps://stackoverflow.com/questions/27375557/hystrix-command-fails-with-timed-out-and-no-fallback-available默認的時間是一秒,然后我們可以看一下這個時間execution.isolation.thread.timeoutInMilliseconds:timeoutInMilliseconds,我們配一下這個東西就OK了# 解決第一次請求報超時異常的方案:
# hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
# 或者:
# hystrix.command.default.execution.timeout.enabled: false
# 或者:
feign.hystrix.enabled: false ## 索性禁用feign的hystrix# 超時的issue:https://github.com/spring-cloud/spring-cloud-netflix/issues/768
# 超時的解決方案: http://stackoverflow.com/questions/27375557/hystrix-command-fails-with-timed-out-and-no-fallback-available
# hystrix配置: https://github.com/Netflix/Hystrix/wiki/Configuration#execution.isolation.thread.timeoutInMillisecondshystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000發現就OK了,這是第一種做法他不是有超時時間嗎,那我把超時時間給禁用掉不就行了,hystrix.command.default.execution.timeout.enabled: false就是不超時,也可以還有一個是最變態,同時也是最徹底的是什么呢,feign.hystrix.enabled: false ## 索性禁用feign的hystrixhttps://github.com/Netflix/Hystrix/wiki/Configuration#execution.isolation.thread.timeoutInMilliseconds可以看他的各種配置execution.isolation.thread.timeoutInMillisecondsexecution.timeout.enabled
?
總結
以上是生活随笔為你收集整理的Fegion-4解决Fegion第一次请求timeout的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Fegion-3覆写Fegion的默认配
- 下一篇: Eureka深入理解