Reputation: 51
I have a WebClient bean defined in my configuration class. It involves a lot of configuration to its connector (including setting SSL, proxy, etc).
@Bean
@Primary
@Scope("prototype")
public WebClient webClient()
{
SslContextBuilder builder = SslContextBuilder.forClient();
HttpClient httpClient = HttpClient
.create(ConnectionProvider.fixed("webClientPool", maxConnections))
...
ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
WebClient webClient = WebClient.builder()
.clientConnector(connector)
.exchangeStrategies(getExchangeStrategies())
.build();
return webClient;
In one of the beans that get this WebClient injected, I want to set different timeouts.
I thought to use webClient.mutate().clientConnector(...)
method, but that would require me to set the whole configuration from scratch just for setting the timeouts.
Unfortunately, WebClient and HttpClient don't have .getxxx() methods that could have helped me copying the old client configuration into the new one.
I want to have a way to set for the mutated WebClient only the timeout option of the tcp-client. Is there a way to do it?
Upvotes: 0
Views: 1168
Reputation: 14820
according to the documentation
WebClient.Builder mutate()
Return a builder to create a new WebClient whose settings are replicated from the current WebClient.
Will return a new builder with all the previous settings set so you don't need to copy anything over.
if you want to minimize configuration as much as possible you can:
define a @Bean
where you configure as much as possible of the HttpClient.Builder
as possible so you can autowire in the HttpClient.Builder later
Then you define 2 webclients that autowire in the httpclient and finish off the httpclient.build() into each webclient.
or you define one webclient and then in the class that needs the modified one you inject in the webclient, and the httpclient.builder and finish the configuration and mutate the webclient.
Upvotes: 1