5

I am using springboot webclient to call rest api from remote server. First request works fine. If I made subsequent request after sometime, the server throws 500 server error. The error I got is " onError(java.io.IOException: An existing connection was forcibly closed by the remote host)".

I want to test the behavior with disabling connection pool since I believe it uses the previous connection. Can you help me how to disable the connection pool when creating webclient?

TcpClient tcpClient = TcpClient.create()
        .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000)
        .option(ChannelOption.SO_KEEPALIVE, false)
        .doOnConnected(connection ->
                connection.addHandlerLast(new ReadTimeoutHandler(30))
                        .addHandlerLast(new WriteTimeoutHandler(30))
        );

ReactorClientHttpConnector httpConnector = new ReactorClientHttpConnector(HttpClient.from(tcpClient));

final WebClient webClient = WebClient
        .builder()
        .clientConnector(httpConnector)
        .baseUrl("http://customer.service.api.internal.cloud.qa.intranet.pagseguro.uol")
        .exchangeStrategies(strategies)
        .build()
4

1 回答 1

8

您可以使用下面的代码禁用连接池

TcpClient tcpClient = TcpClient.newConnection()

用于wiretap(true)检查服务器和客户端之间的流量。

还可以为 Reactor Netty 开启日志记录,跟踪连接是否被重用(在连接池场景中)

logging.level.reactor.netty=debug

如果连接被重用,您将看到

2019-04-11 18:52:10.049 DEBUG 98105 --- [ctor-http-nio-5] r.n.resources.PooledConnectionProvider   : [id: 0x897584fa, L:/<IP>:<PORT> - R:/<IP>:<PORT>] Channel acquired, now 1 active connections and 0 inactive connections

您还可以使用频道 IDid: 0x897584fa跟踪频道的情况。

于 2019-04-11T15:57:05.000 回答