Apache Http客户端响应超时

时间:2019-01-08 01:39:24

标签: apache-httpasyncclient

我正在使用Apache Http Client,并且想知道在响应时间> 3000毫秒的情况下使用哪个API来设置超时。

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpasyncclient</artifactId>
        <version>4.1.4</version>
    </dependency>

以下是我当前的代码-

    RequestConfig requestConfig = RequestConfig.custom().build();

    // Create I/O reactor configuration
    IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
            .setIoThreadCount(ioThreads)
            .setSoKeepAlive(true)
            .build();

    // Create a custom I/O reactort
    ConnectingIOReactor ioReactor = null;

    try {
        ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
    } catch (IOReactorException e) {
        e.printStackTrace();
    }

    PoolingNHttpClientConnectionManager poolingConnectionManager = new PoolingNHttpClientConnectionManager(ioReactor);
    poolingConnectionManager.setMaxTotal(mc);
    poolingConnectionManager.setDefaultMaxPerRoute(mc);

    CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
            .setConnectionManager(poolingConnectionManager)
            .setDefaultRequestConfig(requestConfig)
            .build();

0 个答案:

没有答案