使用HttpAsyncClients设置重试次数

时间:2017-03-02 11:50:00

标签: apache httpclient apache-httpclient-4.x apache-httpasyncclient

使用典型的HttpAsyncClients示例:

public class AsyncClientHttpExchange {

    public static void main(final String[] args) throws Exception {
        CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
        try {
            httpclient.start();
            HttpGet request = new HttpGet("http://httpbin.org/get");
            Future<HttpResponse> future = httpclient.execute(request, null);
            HttpResponse response = future.get();
            System.out.println("Response: " + response.getStatusLine());
            System.out.println("Shutting down");
        } finally {
            httpclient.close();
        }
        System.out.println("Done");
    }
}

如果没有响应,设置重试次数的方法是什么?我可以看到5。

httpClientBuildersetRetryHandler

httpClientBuilder.setRetryHandler(new MyRequestRetryHandler(_maxRetryCount));

HttpAsyncClients的方式是什么?

1 个答案:

答案 0 :(得分:9)

HttpAsyncClient 4.x不支持自动请求重新执行。此功能计划用于HttpAsyncClient 5.0