springcloud中Feign超時(shí)提示Read timed out executing POST的問題及解決方法
springcloud之Feign超時(shí)提示Read timed out executing POST
問題描述:
Feign接口調(diào)用分兩層,Ribbon的調(diào)用
和Hystrix調(diào)用
,理論上設(shè)置Ribbon的時(shí)間
即可,但是Ribbon的超時(shí)時(shí)間和Hystrix的超時(shí)時(shí)間需要結(jié)合起來,按照木桶原則
最低的就是Feign的超時(shí)時(shí)間,建議最好配置超時(shí)時(shí)間一致.當(dāng)
Fegin調(diào)用時(shí),調(diào)用的外部接口,延遲挺大,會(huì)造成Feign一直提示Read timed out executing POST
解決方法:
yml文件中如下配置即可
#hystrix的超時(shí)時(shí)間 hystrix: command: default: execution: timeout: enabled: true isolation: thread: #超時(shí)設(shè)置 timeoutInMilliseconds: 30000 ribbon: ReadTimeout: 30000 #ribbon的超時(shí)時(shí)間 ConnectTimeout: 30000
補(bǔ)充:
spring cloud 調(diào)用feign請求超時(shí) feign.RetryableException: Read timed out executing POST
問題介紹:
服務(wù)之間調(diào)用報(bào)錯(cuò)超時(shí),截取部分報(bào)錯(cuò),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請求報(bào)錯(cuò)超時(shí),feign的調(diào)用分兩層,ribbon的調(diào)用和hystrix的調(diào)用,高版本的hystrix默認(rèn)是關(guān)閉的,所以在application.properties配置文件中設(shè)置ribbon即可
#請求處理的超時(shí)時(shí)間 ribbon.ReadTimeout: 120000 #請求連接的超時(shí)時(shí)間 ribbon.ConnectTimeout: 30000
如果開啟hystrix,hystrix的超時(shí)報(bào)錯(cuò)如下圖:
FeignDemo#demo() timed-out and no fallback available。和ribbon超時(shí)報(bào)錯(cuò)還是有區(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 熔斷機(jī)制 hystrix: shareSecurityContext: true command: default: circuitBreaker: sleepWindowInMilliseconds: 100000 forceClosed: true execution: isolation: thread: timeoutInMilliseconds: 600000
到此這篇關(guān)于springcloud之Feign超時(shí)提示Read timed out executing POST的文章就介紹到這了,更多相關(guān)springcloud Feign超時(shí)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MyBatis-Plus實(shí)現(xiàn)邏輯刪除的示例代碼
本文主要介紹了MyBatis-Plus實(shí)現(xiàn)邏輯刪除的示例代碼,就是通過邏輯判斷的手段表示該條數(shù)據(jù)已刪除,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05Java連接數(shù)據(jù)庫JDBC技術(shù)之prepareStatement的詳細(xì)介紹
這篇文章主要介紹了Java連接數(shù)據(jù)庫JDBC技術(shù)之prepareStatement的詳細(xì)介紹,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07JavaWeb中struts2實(shí)現(xiàn)文件上傳下載功能實(shí)例解析
這篇文章主要介紹了JavaWeb中struts2文件上傳下載功能的實(shí)現(xiàn),在Web應(yīng)用系統(tǒng)開發(fā)中,文件上傳和下載功能是非常常用的功能,需要的朋友可以參考下2016-05-05Java中的Comparable接口與Comparator接口區(qū)別解析
文章介紹了Java中的Comparable接口和Comparator接口,Comparable接口定義了一個(gè)compareTo方法,用于比較對象的順序,實(shí)現(xiàn)Comparable接口的類可以提供自然排序規(guī)則,詳細(xì)介紹了Java中的Comparable接口與Comparator接口區(qū)別,感興趣的朋友一起看看吧2025-02-02SpringSecurity多表多端賬戶登錄的實(shí)現(xiàn)
本文主要介紹了SpringSecurity多表多端賬戶登錄的實(shí)現(xiàn)2024-05-05Spring Cloud Gateway 如何修改HTTP響應(yīng)信息
這篇文章主要介紹了Spring Cloud Gateway 修改HTTP響應(yīng)信息的方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07