3

I have upgraded to spring boot 3. I am trying to instantiate metric binder with pool connection manager.

PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionPerRoute());
connectionManager.setMaxTotal(config.getMaxConnectionPerRoute() * config.getNoOfRoutes());
CloseableHttpClient httpClient = HttpClientBuilder
        .create().setConnectionManager(connectionManager)
        .build();
new PoolingHttpClientConnectionManagerMetricsBinder(connectionManager, "my-pool").bindTo(registry);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
restTemplate = new RestTemplate(requestFactory);

The previously used package

org.apache.http.impl.conn.PoolingHttpClientConnectionManager

The upgraded package

import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;

This updated package is incompatible with PoolingHttpClientConnectionManagerMetricsBinder with issue: 'PoolingHttpClientConnectionManagerMetricsBinder(org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>, java.lang.String, java.lang.String...)' in 'io.micrometer.core.instrument.binder.httpcomponents.PoolingHttpClientConnectionManagerMetricsBinder' cannot be applied to '(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager, java.lang.String)'

I tried to update to the old package

org.apache.http.impl.conn.PoolingHttpClientConnectionManager

and resolve this, but this cause issue with HttpComponentsClientHttpRequestFactory

HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);

as the packages are incompatible 'HttpComponentsClientHttpRequestFactory(org.apache.hc.client5.http.classic.HttpClient)' in 'org.springframework.http.client.HttpComponentsClientHttpRequestFactory' cannot be applied to '(org.apache.http.client.HttpClient)'

Need solution to resolve this or any alternative approach.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176

2 Answers2

1

Both Spring Framework 6 and Spring Boot 3 removed support for HttpComponents 4.x (see this Spring Framework issue and this Spring Boot issue).

If you'd like to keep the connection pool metrics in your application, I would suggest to ask the Micrometer team if they would consider supporting the new version of httpcomponents. Given the latest changes in Micrometer, the HTTP client itself could ship its own, optional, Observability instrumentation like most Spring projects do now.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
0

Seems that Micrometer 1.10.x has done it for httpclient5 but not released yet in 1.10.4 :( https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/httpcomponents/hc5/PoolingHttpClientConnectionManagerMetricsBinder.java Need to wait for next release maybe 1.10.5 will include that.