Reactor-netty: Configure timeout options on HttpClient with new API

Created on 12 Jul 2018  路  2Comments  路  Source: reactor/reactor-netty

With the new HttpClient/TcpClient configuration APIs, I've tried customizing the timeout options for the HTTP client.

While I can change the connection timeout like this:

TcpClient tcpClient = TcpClient.create();
tcpClient.configure()
    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000);
HttpClient httpClient = HttpClient.from(tcpClient);

I cannot find a way to configure the read and write timeouts, as it was previously explained in this StackOverflow answer. Is there still a way (or an easier way) to configure that part of the HttpClient?

fostackoverflow

Most helpful comment

@bclozel You can configure the timeouts like the sample below:

TcpClient tcpClient =
        TcpClient.create()
                 .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
                 .doOnConnected(connection ->
                         connection.addHandlerLast(new ReadTimeoutHandler(10))
                                   .addHandlerLast(new WriteTimeoutHandler(10)));
HttpClient httpClient = HttpClient.from(tcpClient);

All 2 comments

@bclozel You can configure the timeouts like the sample below:

TcpClient tcpClient =
        TcpClient.create()
                 .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
                 .doOnConnected(connection ->
                         connection.addHandlerLast(new ReadTimeoutHandler(10))
                                   .addHandlerLast(new WriteTimeoutHandler(10)));
HttpClient httpClient = HttpClient.from(tcpClient);

Thanks a lot @violetagg !

Was this page helpful?
0 / 5 - 0 ratings