springcloud中Feign超時提示Read timed out executing POST的問題及解決方法
springcloud之Feign超時提示Read timed out executing POST
問題描述:
Feign接口調(diào)用分兩層,Ribbon的調(diào)用
和Hystrix調(diào)用
,理論上設(shè)置Ribbon的時間
即可,但是Ribbon的超時時間和Hystrix的超時時間需要結(jié)合起來,按照木桶原則
最低的就是Feign的超時時間,建議最好配置超時時間一致.當
Fegin調(diào)用時,調(diào)用的外部接口,延遲挺大,會造成Feign一直提示Read timed out executing POST
解決方法:
yml文件中如下配置即可
#hystrix的超時時間 hystrix: command: default: execution: timeout: enabled: true isolation: thread: #超時設(shè)置 timeoutInMilliseconds: 30000 ribbon: ReadTimeout: 30000 #ribbon的超時時間 ConnectTimeout: 30000
補充:
spring cloud 調(diào)用feign請求超時 feign.RetryableException: Read timed out executing POST
問題介紹:
服務之間調(diào)用報錯超時,截取部分報錯,Read timed out executing POST http://******
feign.RetryableException: Read timed out executing POST http://******
at feign.FeignException.errorExecuting(FeignException.java:67)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:104)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
at com.sun.proxy.$Proxy113.getBaseRow(Unknown Source)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at feign.Client$Default.convertResponse(Client.java:152)
at feign.Client$Default.execute(Client.java:74)
原因及解決辦法:
明顯可以看到是http請求報錯超時,feign的調(diào)用分兩層,ribbon的調(diào)用和hystrix的調(diào)用,高版本的hystrix默認是關(guān)閉的,所以在application.properties配置文件中設(shè)置ribbon即可
#請求處理的超時時間 ribbon.ReadTimeout: 120000 #請求連接的超時時間 ribbon.ConnectTimeout: 30000
如果開啟hystrix,hystrix的超時報錯如下圖:
FeignDemo#demo() timed-out and no fallback available。和ribbon超時報錯還是有區(qū)別的
com.netflix.hystrix.exception.HystrixRuntimeException: FeignDemo#demo() timed-out and no fallback available.
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:819)
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:804)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1472)
at com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1397)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.observers.Subscribers$5.onError(Subscribers.java:230)
Caused by: java.util.concurrent.TimeoutException
at com.netflix.hystrix.AbstractCommand.handleTimeoutViaFallback(AbstractCommand.java:997)
at com.netflix.hystrix.AbstractCommand.access$500(AbstractCommand.java:60)
at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:610)
at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:601)
解決辦法:
feign.hystrix.enabled: true hystrix 熔斷機制 hystrix: shareSecurityContext: true command: default: circuitBreaker: sleepWindowInMilliseconds: 100000 forceClosed: true execution: isolation: thread: timeoutInMilliseconds: 600000
到此這篇關(guān)于springcloud之Feign超時提示Read timed out executing POST的文章就介紹到這了,更多相關(guān)springcloud Feign超時內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java連接數(shù)據(jù)庫JDBC技術(shù)之prepareStatement的詳細介紹
這篇文章主要介紹了Java連接數(shù)據(jù)庫JDBC技術(shù)之prepareStatement的詳細介紹,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-07-07JavaWeb中struts2實現(xiàn)文件上傳下載功能實例解析
這篇文章主要介紹了JavaWeb中struts2文件上傳下載功能的實現(xiàn),在Web應用系統(tǒng)開發(fā)中,文件上傳和下載功能是非常常用的功能,需要的朋友可以參考下2016-05-05Java中的Comparable接口與Comparator接口區(qū)別解析
文章介紹了Java中的Comparable接口和Comparator接口,Comparable接口定義了一個compareTo方法,用于比較對象的順序,實現(xiàn)Comparable接口的類可以提供自然排序規(guī)則,詳細介紹了Java中的Comparable接口與Comparator接口區(qū)別,感興趣的朋友一起看看吧2025-02-02SpringSecurity多表多端賬戶登錄的實現(xiàn)
本文主要介紹了SpringSecurity多表多端賬戶登錄的實現(xiàn)2024-05-05Spring Cloud Gateway 如何修改HTTP響應信息
這篇文章主要介紹了Spring Cloud Gateway 修改HTTP響應信息的方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07