Siqi Li created HTTPCLIENT-2349:
-----------------------------------

             Summary: [Question] How do I set connect timeout per request with 
the async client?
                 Key: HTTPCLIENT-2349
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2349
             Project: HttpComponents HttpClient
          Issue Type: Wish
          Components: HttpClient (async)
    Affects Versions: 5.4
            Reporter: Siqi Li


So the library allows me to set the default connection request timeout, request 
timeout, and connect timeout on the client level. But since the 
setConnectTimeout method in RequestConfig.Builder is deprecated, I have not 
found a way of setting the connect timeout per request. Is there a way of doing 
it? Or am I stuck with setting the connect timeout on the client level?

Here's a code example to demonstrate what I mean.
{code:java}
public static void main(String[] args) throws Exception {
  try (CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.custom()
      .setDefaultRequestConfig(RequestConfig.custom()
          .setConnectionRequestTimeout(1, TimeUnit.MINUTES)
          .setResponseTimeout(1, TimeUnit.MINUTES)
          // This is deprecated, but I can set it with setConnectionManager 
below
          //.setConnectTimeout(1, TimeUnit.MINUTES)
          .build())
      .setConnectionManager(PoolingAsyncClientConnectionManagerBuilder.create()
          .setDefaultConnectionConfig(ConnectionConfig.custom()
              // I guess this is the preferred way of setting the connect 
timeout on the client level
              .setConnectTimeout(1, TimeUnit.MINUTES)
              .setSocketTimeout(1, TimeUnit.MINUTES)
              .build())
          .build())
      .build()) {
    SimpleRequestBuilder.get("https://example.com";)
        .setRequestConfig(RequestConfig.custom()
            .setConnectionRequestTimeout(5, TimeUnit.SECONDS)
            .setResponseTimeout(5, TimeUnit.SECONDS)
            // This is deprecated. What's the replacement if I want to set the 
connect timeout per request?
            .setConnectTimeout(5, TimeUnit.SECONDS)
            .build())
        .build();
  }
}{code}
Thanks!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to