1

我想使用退避重试机制来发送 http 请求列表。

有什么方法可以标记(带有标志)仅在重试后成功的请求?

我看到了几个解决方案:

1) https://github.com/rholder/guava-retrying

2) https://developers.google.com/api-client-library/java/google-http-java-client/backoff

但没有办法整合这个标记。这些库中有任何其他库或想法吗?

我试图覆盖这个方法,但是没有办法返回那个指示标志

@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;
  }
4

1 回答 1

0

检查故障安全。如果您希望将请求标记为成功,则可以使用事件处理程序。

于 2016-03-31T05:19:01.203 回答