如何迁移到低于 Apache httpcomponents-client 5.x 的 setRetryStrategy
HttpClientBuilder cb = HttpClients.custom();
cb.setRetryHandler(new DefaultHttpRequestRetryHandler(X, true));
最新的DefaultHttpRequestStrategy中没有requestSentRetryEnabled的参数
迁移到 httpcomponents-client 5.x
requestSentRetryEnabled不是必需的,如果您将RetryHandler设置为DefaultHttpRequestStrategy,如果错误是下面的503示例代码,它将重试
public static void main(String[] args) throws IOException {
final ClassicHttpRequest httpGet = ClassicRequestBuilder.get("https://httpbin.org/status/503")
.build();
CloseableHttpClient httpClient = HttpClientBuilder
.create()
.setRetryStrategy(new DefaultHttpRequestRetryStrategy(3, TimeValue.ofSeconds(3)))
.build();
httpClient.execute(httpGet, response -> {
System.out.println(response.getCode() + " " + response.getReasonPhrase());
return null;
});
}
如果您想查看更多自定义策略,请重试所有检查此处。