as i undestand one benefit of using spring 4 restclient group service is to shared common client config. i am working on microservice system with several services,... each call others through rest api. i need to set different connection timeout for each group(currently set it through applicataion.yml) . also some client should be called via secure ssl channel (again through setting ssl bundle properties in application.yml). but i have some global config witch should be shared by all groups like status handle interceptor and connection pool. i could add my custom interceptor as i show below:
@Bean
public RestClientHttpServiceGroupConfigurer globalConfigurer(
ClientRequestTraceIdService clientRequestTraceIdService,
JsonMapper jsonMapper
) {
return groups -> {
groups.forEachClient((group, client) -> {
client.requestInterceptor(clientRequestTraceIdService)
.defaultStatusHandler(
HttpStatusCode::isError, new GlobalRestClientErrorHandler(jsonMapper)
);
});
};
}
but i have problem to config connection pool when i use ClientHttpRequestFactoryBuilder like below. when i use the following config my application.yml properties overrided.
@Bean
PoolingHttpClientConnectionManager poolingHttpClientConnectionManager(
@Value("${rest-client.connection.max-total:150}") Integer maxTotalConnection,
@Value("${rest-client.connection.max-per-route:50}") Integer maxPerRouteConnection
) {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(maxTotalConnection);
cm.setDefaultMaxPerRoute(maxPerRouteConnection);
return cm;
}
@Bean
ClientHttpRequestFactoryBuilder<?> clientHttpRequestFactoryBuilder(
PoolingHttpClientConnectionManager connectionManager) {
return ClientHttpRequestFactoryBuilder.httpComponents()
.withHttpClientCustomizer(httpClientBuilder ->
httpClientBuilder.setConnectionManager(connectionManager)
);
}
@Bean
public RestClientHttpServiceGroupConfigurer globalConfigurer(
ClientRequestTraceIdService clientRequestTraceIdService,
JsonMapper jsonMapper,
ClientHttpRequestFactoryBuilder<?> clientHttpRequestFactoryBuilder
) {
return groups -> {
groups.forEachClient((group, client) -> {
client.requestInterceptor(clientRequestTraceIdService)
.requestFactory(clientHttpRequestFactoryBuilder.build())
.defaultStatusHandler(
HttpStatusCode::isError, new GlobalRestClientErrorHandler(jsonMapper)
);
});
};
}
as i undestand one benefit of using spring 4 restclient group service is to shared common client config. i am working on microservice system with several services,... each call others through rest api. i need to set different connection timeout for each group(currently set it through applicataion.yml) . also some client should be called via secure ssl channel (again through setting ssl bundle properties in application.yml). but i have some global config witch should be shared by all groups like status handle interceptor and connection pool. i could add my custom interceptor as i show below:
but i have problem to config connection pool when i use
ClientHttpRequestFactoryBuilderlike below. when i use the following config my application.yml properties overrided.