Skip to content

Java Specific webclient connect timeout per request

I have to call different urls with different connection timeout with webclient. But i found that we can set connect timeout globally only and not per resquest .. what to do please to set this timeout on a request without creating a new weblient each time.



You need to instantiate one webclient per url. For each webclient, you can set the connection timeout :

HttpClient httpClient = HttpClient.create()
  .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
WebClient client = WebClient.builder()
  .clientConnector(new ReactorClientHttpConnector(httpClient))

Then reuse this webclient for all the calls to the configured url.