使用HttpAsyncClients设置重试次数

Joh*_*ria 4 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");
    }
}
Run Code Online (Sandbox Code Playgroud)

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

随着httpClientBuilder存在setRetryHandler:

httpClientBuilder.setRetryHandler(new MyRequestRetryHandler(_maxRetryCount));
Run Code Online (Sandbox Code Playgroud)

有什么办法HttpAsyncClients

ok2*_*k2c 9

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