Hello Mates,

1. In RequestConfig: What is the difference between ConnectTimeout and 
ConnectionRequestTimeout ?
From quick look at code - I concluded that ConnectTimeout is "timeout when 
client tries to connect to server" and ConnectionRequestTimeout is "timeout 
when request can be considered expired". 

2. How can I set connection manager timeout ? This time out implies if all 
connections are busy/leased, it will wait for specified time in queue before 
returning timeout error. Please correct if my understanding is wrong.
 Previously I used httpparams to do that. But now httpparams seems to be have 
deprecated.
// timeout waiting for a connection from the connection manager. 
httpParams.setParameter("http.connection-manager.timeout", (int) 
config.getConnectionManagerTimeout()
        .toMillis());

3. How can I set HttpVersion ?
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);

4. Also I noticed that socket/connection timeouts are configured at multiple 
places. Hence would like to make sure what is best practice to configure them. 
Should we set at all below 3 places ?
1. IOReactorConfig has sockettimeout and connection timeout 
2. SocketConfig which can be set to PoolingNHttpClientConnectionManager
3. RequestConfig - also has both Socket and Connection timeout setting.

Code:

PoolingNHttpClientConnectionManager connectionManager;
try {
    DefaultConnectingIOReactor ioreactor = new DefaultConnectingIOReactor();
    connectionManager = new PoolingNHttpClientConnectionManager(ioreactor);
} catch (IOReactorException e) {
    throw new RuntimeException(e);
}

SocketConfig socketConfig = SocketConfig.custom().setSoTimeout((int) 
config.getSocketTimeOut().toMillis()).setTcpNoDelay(true).build();
ConnectionConfig connectionConfig = 
ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build();
RequestConfig requestConfig = 
RequestConfig.custom().setCircularRedirectsAllowed(true)
        .setConnectTimeout((int) config.getConnectionTimeOut().toMillis())
        .setConnectionRequestTimeout((int) 
config.getConnectionTimeOut().toMillis())
        .setSocketTimeout((int) config.getSocketTimeOut().toMillis())
        .build();

connectionManager.setDefaultSocketConfig(socketConfig);
connectionManager.setDefaultConnectionConfig(connectionConfig);

HttpAsyncClientBuilder asyncHttpClientBuilder = HttpAsyncClientBuilder.create();
asyncHttpClientBuilder.setConnectionManager(connectionManager);
asyncHttpClientBuilder.setUserAgent("xyz");
asyncHttpClientBuilder.setDefaultRequestConfig(requestConfig);
HttpAsyncClient client = asyncHttpClientBuilder.build();

Thanks,
Jaikit

Reply via email to