Amazon Web Services中的API重试逻辑 [英] API retry logic in Amazon Web Services

查看:145
本文介绍了Amazon Web Services中的API重试逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://docs.aws.amazon.com/ general / latest / gr / api-retries.html

该文档提到每个AWS开发工具包都实现了自动重试逻辑,而AWS SDK for Java会自动重试请求。

This document mentions that "each AWS SDK implements automatic retry logic and AWS SDK for Java automatically retries requests."

如果我未指定任何重试配置,Java AWS SDK的默认机制是什么?我一直在使用Java AWS开发工具包,如果AWS服务端发生故障,则会得到直接的服务异常。我从未经历过任何自动重试机制。有人可以解释一下这种重试机制是什么?

What is the default mechanism for Java AWS SDK, if i don't specify any retry config? I have been using the Java AWS SDK and get a straightforward service exception if something fails on AWS service side. I have never experienced any "automatic" retry mechanism. Can someone explain what this retry mechanism is?

推荐答案

同一文档页面说:


适用于Java的AWS开发工具包会自动重试请求,您可以使用 ClientConfiguration 类配置重试设置。

您应查看 ClientConfiguration ,它有很多方法可以调整有关重试逻辑的行为。这里是最重要的:

You should check the official documentation for ClientConfiguration, it has plenty of methods to tune its behaviour regarding retry logic. Here are the most important:


  • withMaxErrorRetry 设置失败的最大重试次数可重试的请求(例如:服务的5xx错误响应)

  • withRequestTimeout 设置等待时间(以毫秒为单位)在放弃和超时之前完成的请求[...]

  • withThrottledRetries 重试限制功能是一项功能当大量请求失败时,智能地限制重试尝试g和重试失败[...]

  • withRetryPolicy 这是最有趣的,它允许您选择 RetryPolicy 并更改:


    • BackoffStrategy 用于提供自定义补偿的挂钩控制重试之间的睡眠时间的策略

    • RetryCondition 用于提供有关是否失败的自定义条件的挂钩请求应重试

    • maxErrorRetry

    • honorMaxErrorRetryInClientConfig (是否遵守上述配置设置)

    • withMaxErrorRetry Sets the maximum number of retry attempts for failed retryable requests (ex: 5xx error responses from services)
    • withRequestTimeout Sets the amount of time to wait (in milliseconds) for the request to complete before giving up and timing out [...]
    • withThrottledRetries Retry throttling is a feature which intelligently throttles retry attempts when a large percentage of requests are failing and retries are unsuccessful [...]
    • withRetryPolicy This is the most interesting, it allows you to choose RetryPolicy and change:
      • BackoffStrategy The hook for providing custom back-off strategy to control the sleep time between retries
      • RetryCondition The hook for providing custom condition on whether a failed request should be retried
      • maxErrorRetry
      • honorMaxErrorRetryInClientConfig (whether to respect the configuration setting mentioned above)

      还请注意,如果您没有注意到自动重试机制,则可能是由于客户端错误所致。这些设置仅用于在服务器(5xx)或限制错误的情况下重试请求:

      Also note that if you haven't noticed the automatic retry mechanism, it could be due to the client-side errors. These settings are only for retrying requests in case of server (5xx) or throttling errors:


      客户端错误(4xx)表示您需要在再次尝试之前修改请求以更正问题。

      client errors (4xx) indicate that you need to revise the request to correct the problem before trying again

      如果您声称这是服务端失败,则应提供一些代码再现情况并分析实际情况。

      If you claim that it were "service side" fails, you should provide some code to reproduce the situation and analyze what is actually happening.

      现在有关默认值:


      如果我不指定任何重试配置,Java SDK的默认机制是什么?

      What is the default mechanism for Java SDK, if i don't specify any retry config?

      您可以查找 ClientConfiguration 常量字段。但是请注意,它可能会因您使用的服务而有所不同(特别是DynamoDB是特例)。还请检查 PredefinedClientConfigurations PredefinedRetryPolicies 类。

      You can lookup the default values of the ClientConfiguration constant fields. But note, that it may differ depending on the service you use (in particular DynamoDB is a special case). Check also PredefinedClientConfigurations and PredefinedRetryPolicies classes.

      这篇关于Amazon Web Services中的API重试逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆