为了账号安全,请及时绑定邮箱和手机立即绑定

使用 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 关注
  • 155 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号