亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Spring-ws 和 4.5.x Http 客戶端忽略 DNS 輪詢以獲得可靠的超時

使用 Spring-ws 和 4.5.x Http 客戶端忽略 DNS 輪詢以獲得可靠的超時

陪伴而非守候 2021-12-10 14:52:37
我們正在使用帶有 Spring-Ws 的 Http Client 4.5.x 并使用該webServiceTemplate.marshalSendAndReceive(requestObject)方法發出請求。我們想要一個可靠的連接超時值,但目前遇到了第 8 節(DNS 循環)中描述的問題,其中嘗試了多個 IP 地址,因此超時是不可預測的。是否有簡單的方法可以僅使用 Spring-ws 和 Http Client 庫在一段時間后設置硬超時,或者是否需要設置某種自定義超時?案例:連接超時設置為 1 秒(該方法的實際超時為 4 秒——是否可以使用 Spring/Http 客戶端庫將方法超時設置為 1 秒?)應用程序日志(Http 客戶端日志設置為DEBUG):16:45:02 (org.apache.http.impl.execchain.MainClientExec) Opening connection {}->http://salesforce.com:448 16:45:02 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connecting to salesforce.com/96.43.149.26:448 16:45:03 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connect to salesforce.com/96.43.149.26:448 timed out. Connection will be retried using another IP address 16:45:03 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connecting to salesforce.com/96.43.145.26:448 16:45:04 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connect to salesforce.com/96.43.145.26:448 timed out. Connection will be retried using another IP address 16:45:04 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connecting to salesforce.com/96.43.144.26:448 16:45:05 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connect to salesforce.com/96.43.144.26:448 timed out. Connection will be retried using another IP address 16:45:05 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connecting to salesforce.com/96.43.148.26:44816:45:06 (org.apache.http.impl.conn.DefaultManagedHttpClientConnection) http-outgoing-0: Shutdown connection Http客戶端bean:<bean id="httpClientBean" class="org.apache.http.client.HttpClient" factory-bean="httpClientFactory" factory-method="getHttpClient" />服務代碼(我們希望這個方法調用需要 X 秒,而不是 2x 或 3x 秒):// we want this method call to take ~1 second, not ~4 seconds (i.e. similar to the connection timeout value, not a multiplier)Object obj = webServiceTemplate.marshalSendAndReceive(requestDocument);
查看完整描述

1 回答

?
蠱毒傳說

TA貢獻1895條經驗 獲得超3個贊

有兩種選擇


建立自定義 ClientConnectionOperator


構建自定義DnsResolver. 這個選項要簡單得多。


CloseableHttpClient client = HttpClients.custom()

   .setDnsResolver(host -> new InetAddress[] { InetAddress.getByName(host) })

   .build();


查看完整回答
反對 回復 2021-12-10
  • 1 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號