I'm using the following config to create a RestTemplate
bean.
@Bean
@Primary
public RestTemplate restTemplate(RestTemplateBuilder builder) {
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
return builder.requestFactory(() -> new BufferingClientHttpRequestFactory(factory))
.build();
}
Problem: by default HttpClient
is instantiated as follows:
org.apache.http.impl.client.HttpClientBuilder:
String s = System.getProperty("http.keepAlive", "true");
if ("true".equalsIgnoreCase(s)) {
s = System.getProperty("http.maxConnections", "5");
int max = Integer.parseInt(s);
poolingmgr.setDefaultMaxPerRoute(max);
poolingmgr.setMaxTotal(2 * max);
}
Thus by default having a maximum of 10 concurrent url connections on that rest template.
Question: how could I best configure the max total when using spring-boot
? I did not find any application.properties
entry to set it to a custom value.
Sidequestion: what does the property per route mean? Is a route localhost:8080/myfirst
, and another route is localhost:8080/mysnd
? Or are both the same route localhost:8080
?