[英]Spring Boot 3 Micrometer Integration with RestTemplate
我已經升級到spring boot 3 。 我正在嘗試使用池連接管理器實例化度量活頁夾。
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);
之前使用的package
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
升級后的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' 不能應用於 '(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager, 8821324.6945888)8
我試着更新到舊的 package
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
並解決這個問題,但這會導致 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)'
需要解決此問題或任何替代方法的解決方案。
Spring Framework 6 和 Spring Boot 3 都刪除了對 HttpComponents 4.x 的支持(請參閱此Spring Framework 問題和此 Spring Boot 問題)。
如果您想在應用程序中保留連接池指標,我建議您詢問 Micrometer 團隊是否會考慮支持新版本的 httpcomponents。 考慮到 Micrometer 的最新變化,HTTP 客戶端本身可以像大多數 Spring 項目現在做的那樣提供自己的、可選的、可觀察性工具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.