提示:文章寫完后,目錄可以自動(dòng)生成,如何生成可參考右邊的幫助文檔
背景
1、項(xiàng)目升級到Springboot3,使用WebFlux自帶的WebClient作為HTTP客戶端
2、接口類客戶端方式調(diào)用外部服務(wù),默認(rèn)超時(shí)5S
3、需根據(jù)業(yè)務(wù)動(dòng)態(tài)修改超時(shí)時(shí)間,如60S
報(bào)錯(cuò)如下:
java.lang.IllegalStateException: Timeout on blocking read for 5000000000 NANOSECONDS
博客內(nèi)容精選:
1、Servlet請求體重復(fù)讀&修改新姿勢
2、根據(jù)請求獲取后端接口詳情
3、封裝Springboot項(xiàng)目的starter-sdk新方式
4、Springboot全局處理完整版
5、itextpdf讀取文本時(shí)上下行位置錯(cuò)亂
6、JAVA讀取PDF表格內(nèi)容文章來源:http://www.zghlxwxcb.cn/news/detail-531301.html
一、代碼示例
@Bean
public Inferface interfaceStreamApi() {
WebClient client = WebClient.builder().baseUrl(baseAddress).build();
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).blockTimeout(Duration.ofSeconds(60)).build();
return factory.createClient(Inferface.class);
}
總結(jié)
接口方式使用WebClient創(chuàng)建HTTP請求,底層使用reactor-core中的Mono方式請求,無法直接配置Mono的超時(shí)時(shí)間。HttpServiceProxyFactory為封裝最上層,blockTimeout配置親測有效,初始使用reactor.netty.http.client.HttpClient.responseTimeout配置超時(shí)無效(版本回退+1)文章來源地址http://www.zghlxwxcb.cn/news/detail-531301.html
到了這里,關(guān)于【W(wǎng)ebClient】客戶端HTTP 超時(shí)配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!