Jersey 2.7 - 设置重试处理程序

Mic*_*zyk 5 java apache jax-rs jersey-client jersey-2.0

我想为Jersey客户端利用设置一个重试处理程序ApacheConnector.我希望这样做,因为我希望它在超时时重试(我的HAProxy会将其切换到另一台服务器).我不知道如何做到这一点Jersey 2.7.

示例代码:

public static void Example() {

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.connectorProvider(new ApacheConnectorProvider());
    clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager());

    RequestConfig reqConfig = RequestConfig.custom().build(); 
    clientConfig.property(ApacheClientProperties.REQUEST_CONFIG, reqConfig);

    Client client = ClientBuilder.newClient(clientConfig);
    WebTarget apiTarget = client.target("http://127.0.0.1/rest");
    System.out.println(apiTarget.path(ApiConstant.PING)
            .path(ApiConstant.PING1)
            .request(MediaType.TEXT_PLAIN)
            .get(String.class));
}
Run Code Online (Sandbox Code Playgroud)

如果使用此代码,如果服务器响应错误,我可以设置重试处理程序再次发送请求?可能吗?