spring-webfluxproject-reactorspring-webclientreactor-netty

HTTPClient recomendations


I created a webclient customizer that creates a HTTPClient with a custom ConnectionProvider

    @Bean
    WebClientCustomizer webClientCustomizer(CustomizableWebClientProperties properties) {
        return builder -> {
            var connectionProvider = ConnectionProvider
                .builder("customizable-webclient-connection-provider")
                .maxConnections(properties.maxConnections())
                .maxIdleTime(properties.maxIdleTimeout())
                .build();
            var httpClient = HttpClient.create(connectionProvider).compress(true);
            httpClient.warmup().block();
            if (properties.wiretap()) {
                httpClient = httpClient.wiretap("uk.co.something.webclient", LogLevel.DEBUG, TEXTUAL, UTF_8);
            }
            var connector = new ReactorClientHttpConnector(httpClient);
            builder.clientConnector(connector);
        };
    }

And I have several questions:

Appart from those, any other recommendation is more than welcome!


Solution

  • If the scenario allows, it is always better to share common resources as LoopResource, ConnectionProvider, SslContext etc. By default, if there is no explicit configuration, Reactor Netty will share those.

    The same applies for HttpClient and WebClient. If the scenario allows, it is always better to share HttpClient and WebClient.