我想使用退避重试机制
发送http请求列表。
有什么方法可以标记(带标志)仅在重试后成功的请求吗?
我看到了一些解决方案:
1)https://github.com/rholder/guava-retrying
2)https://developers.google.com/api-client-library/java/google-http-java-client/backoff
但看不到整合这种衰退的方法。这些libs中还有其他的lib或idea吗?
我试图重写此方法,但无法返回指示标志
@Beta
public class HttpBackOffUnsuccessfulResponseHandler implements HttpUnsuccessfulResponseHandler {
* {@inheritDoc}
*
* <p>
* Handles the request with {@link BackOff}. That means that if back-off is required a call to
* {@link Sleeper#sleep(long)} will be made.
* </p>
*/
public final boolean handleResponse(
HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException {
if (!supportsRetry) {
return false;
}
// check if back-off is required for this response
if (backOffRequired.isRequired(response)) {
try {
return BackOffUtils.next(sleeper, backOff);
} catch (InterruptedException exception) {
// ignore
}
}
return false;
}
最佳答案
查看Failsafe。如果希望将请求标记为成功,则可以使用事件处理程序。
关于java - 我有什么办法可以标记“仅在重试后才能成功”的任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35634970/