Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marciorodrigues87/2b86b7d7ba2885d61663c9cf708c0dcf to your computer and use it in GitHub Desktop.
Save marciorodrigues87/2b86b7d7ba2885d61663c9cf708c0dcf to your computer and use it in GitHub Desktop.
RestTemplateConfigStepSix.java
final RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(100) // <--
.setConnectTimeout(500) // <--
.setSocketTimeout(1000) // <--
.build();
final HttpClient httpClient = HttpClients.custom()
.setMaxConnPerRoute(100)
.setMaxConnTotal(1000)
.setConnectionTimeToLive(30, MINUTES)
.setRetryHandler((IOException exception, int executionCount, HttpContext context) -> {
return executionCount <= 3;
})
.setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(3, 1))
.setDefaultRequestConfig(requestConfig) // <--
.build();
final RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment