Есть способ сделать то же самое для Оставьте шаблон, настроив PoolingHttpClientConnectionManager.
Код: Выделить всё
public Map getMetrics() {
final Map gauges = new HashMap();
for (Entry entry : connectionManagerMap
.entrySet()) {
gauges.put(entry.getKey() + ".leasedConnections",
(Gauge) () -> entry.getValue().getTotalStats().getLeased());
gauges.put(entry.getKey() + ".maxConnections",
(Gauge) () -> entry.getValue().getTotalStats().getMax());
gauges.put(entry.getKey() + ".pendingConnections",
(Gauge) () -> entry.getValue().getTotalStats().getPending());
gauges.put(entry.getKey() + ".availableConnections",
(Gauge) () -> entry.getValue().getTotalStats().getAvailable());
}
return gauges;
}
Код: Выделить всё
WebClient webClient = WebClient.builder()
.baseUrl(downstream.getServiceLocation())
.clientConnector(clientHttpConnector)
.exchangeStrategies(exchangeStrategies)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE)
.build();
**and clientHttpConnector was created:**
public ClientHttpConnector lbosClientHttpConnector() {
return new ReactorClientHttpConnector(options -> {
options.option(ChannelOption.SO_TIMEOUT, applicationConfiguration.getDownstreams().getHttpClient().getSocketTimeout());
options.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, applicationConfiguration.getDownstreams().getHttpClient().getKeepAliveTimeoutInMs());
options.poolResources(PoolResources.fixed("HTTP_CONNECTION_POOL", applicationConfiguration.getDownstreams().getHttpClient().getMaxConnections()));
});
}
Подробнее здесь: https://stackoverflow.com/questions/551 ... -webclient