I was creating HttpComponentsMessageSender bean as below
@Bean
public HttpComponentsMessageSender reservationHttpComponent() {
HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender();
httpComponentsMessageSender.setConnectionTimeout(reservationConnectionTimeOut);
httpComponentsMessageSender.setReadTimeout(reservationReadTimeOut);
return httpComponentsMessageSender;
}
Here I was getting Intermittent Read Time Out Issue - Like if I try for 1st time after a 30 mins break I was getting read time out, afterwards all further transactions are successful. If again take 30 mins break then again 1st transaction failed with read time out issue and then all further are successful...
I tried fixing as below code -
@Bean
public HttpComponentsMessageSender reservationHttpComponent() {
RequestConfig requestBuilder = RequestConfig.custom()
.setSocketTimeout(reservationReadTimeOut)
.setConnectionRequestTimeout(reservationConnectionTimeOut)
.setConnectTimeout(reservationConnectionTimeOut)
.setCircularRedirectsAllowed(false)
.build();
org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create()
.setConnectionManager(getConnManager())
.addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor())
.setDefaultRequestConfig(requestBuilder)
.build();
HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender();
messageSender.setHttpClient(httpClient);
return messageSender;
}
private PoolingHttpClientConnectionManager getConnManager() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultMaxPerRoute(connectionManagerDefaultMaxPerRoute);
connectionManager.setMaxTotal(connectionManagerMaxTotal);
connectionManager.setDefaultSocketConfig(SocketConfig.custom()
.setSoTimeout(reservationReadTimeOut).build());
return connectionManager;
}
Above has resolved the Read time out issue but then I have started getting below issue-
message:Error Occurred While Retrieving Reservation - I/O error: Timeout waiting for connection from pool; nested exception is org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
I am looking for the fix and then I tried initializing PoolingHttpClientConnectionManager with TTL -
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(1, TimeUnit.MINUTES)
Then I ran multiple performance jmx script where I have fired 70 - 80 TPS on my service that have above code for external dependency and all looks good.
However I am not sure if having TTL in PoolingHttpClientConnectionManager constructor is the very appropriate solution.. So here I am looking for suggestions on if this solution can cause any further issue or any this else could that be a better approach than this.