Timeouts

edit

Configuring requests timeouts can be done by providing an instance of RequestConfigCallback while building the RestClient through its builder. The interface has one method that receives an instance of org.apache.http.client.config.RequestConfig.Builder as an argument and has the same return type. The request config builder can be modified and then returned. In the following example we increase the connect timeout (defaults to 1 second) and the socket timeout (defaults to 10 seconds). Also we adjust the max retry timeout accordingly (defaults to 10 seconds too).

RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200))
        .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
            @Override
            public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
                return requestConfigBuilder.setConnectTimeout(5000)
                        .setSocketTimeout(30000);
            }
        })
        .setMaxRetryTimeoutMillis(30000)
        .build();