我们需要无限期地保持连接打开并重新连接,以防找不到来自服务器的响应或任何错误。
我们正在考虑使用 IdleStateHandler 和 HeartbeatHandler 来实现相同的功能,但编写代码有困难。有人可以帮助我们使用伪代码或一些帮助来实现相同的目标。这就是我们迄今为止所拥有的。
ConnectionProvider elasticPool = ConnectionProvider.elastic("productDef-pool");
HttpClient httpClient = HttpClient
.create(elasticPool)
.keepAlive(true)
.tcpConfiguration(tcpClient ->
tcpClient.doOnConnected(connection -> {
if (connection.channel().pipeline().get("write_timeout") == null)
connection
.channel()
.pipeline()
.addFirst("write_timeout", new WriteTimeoutHandler(10, TimeUnit.MINUTES));
if (connection.channel().pipeline().get("read_timeout") == null)
connection
.channel()
.pipeline()
.addFirst("read_timeout", new ReadTimeoutHandler(10, TimeUnit.MINUTES));
}))
.wiretap(true);
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient))
.defaultHeader("Authorization", "1")
.defaultHeader("Trace_Id", "3")
.defaultHeader("Span_Id", "4")
.defaultHeader("Accept", "application/json")
.filter(hmacHeaderExchangeFilter)
.baseUrl("https://productdef-dev.test.com")
.build();