cf-java-client icon indicating copy to clipboard operation
cf-java-client copied to clipboard

Better customization options for the underlying HTTP client

Open nictas opened this issue 5 years ago • 1 comments
trafficstars

We're using the CF Java client under a fairly high load (tens of thousands of requests per day) and we would like to enable the metrics feature of reactor-netty, so that we can see how many connections are used at any point in time:

return createHttpClient().compress(true) // Code taken from _DefaultConnectionContext.java
            .tcpConfiguration(this::configureTcpClient)
            .secure(this::configureSsl)
            .metrics(true, new CustomHttpClientMetricsRecorder());

This is currently not possible unless we also override the entire reactor-netty client via DefaultConnectionContext.builder().httpClient(...), which we don't want to do, because it would involve to copy-pasting the entire HttpClient building logic from _DefaultConnectionContext. I could make a pull request that allows users of the CF Java client to do:

DefaultConnectionContext.builder()
    .metrics(true) // OR
    .metrics(true, new CustomHttpClientMetricsRecorder())
    .build();

But I also don't particularly like that idea, because this doesn't cover any future features that the rector-netty devs may implement (or already have implemented). Maybe something like the following would be best?

DefaultConnectionContext.builder()
    .additionalHttpClientConfiguration(httpClient -> httpClient.metrics(true) // OR
        .metrics(true, new CustomHttpClientMetricsRecorder()))
    .build();

What do you think?

nictas avatar Dec 06 '19 12:12 nictas

Sorry for the delay. If this is still something you're considering, +1 for the second approach a callback for customizing.

I would prefer a name like httpClientCustomizer or httpClientConfigurer for the reason that if I'm developing in an IDE with IntelliSense, my first inclination would be to look for something in the pop up related to "http client", so having that at the beginning would make it easier to find. I'm open to another name though if there's a practical reason behind it (like following a naming convention of Spring or Spring Boot).

dmikusa avatar Jan 18 '22 17:01 dmikusa