-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
支持类似spring-retry的请求失败重试吗? #15
Labels
question
Further information is requested
Comments
构建 HTTP 实例的时候添加一个拦截器就可以实现啦 |
有示例吗?发来学习下! |
HTTP http = HTTP.builder()
.config(builder -> {
builder.connectTimeout(10, TimeUnit.MILLISECONDS);
builder.readTimeout(10, TimeUnit.MILLISECONDS);
builder.writeTimeout(10, TimeUnit.MILLISECONDS);
builder.addInterceptor(chain -> {
int retryTimes = 0;
while (true) {
try {
return chain.proceed(chain.request());
} catch (SocketTimeoutException e) {
if (retryTimes >= 3) {
throw e;
}
retryTimes++;
System.out.println("超时重试第" + retryTimes + "次!");
}
}
});
}).build();
HttpResult res = http.sync("https://www.baidu.com").get();
System.out.println(res.getBody().toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
支持类似spring-retry的请求失败重试吗?
如:请求timeout时,可自动重试几次。
The text was updated successfully, but these errors were encountered: