Configure a retry policy

更新时间:
复制 MD 格式

Cloud-native API Gateway lets you configure a route-level retry policy to automatically retry failed requests. You can specify the retry conditions, such as a connection failure, an unavailable backend service, or a response with a specific HTTP status code.

Retry conditions

When a backend service returns a 5xx error, Cloud-native API Gateway automatically retries the failed request based on the configured number of retries.

image
  • The following are the retry conditions for the HTTP protocol:

    • 5xx: If the backend service returns any 5xx response, or if a connection is disconnected, reset, or times out during a read operation, Cloud-native API Gateway retries the request.

      Note

      The 5xx condition includes the connect-failure and refused-stream conditions.

    • reset: If a connection is disconnected, reset, or times out during a read operation, Cloud-native API Gateway retries the request.

    • connect-failure: If a request fails because the connection is disconnected, Cloud-native API Gateway retries the request.

    • refused-stream: If the backend service resets a stream with a REFUSED_STREAM error code, Cloud-native API Gateway retries the request.

    • retriable-status-codes: If the HTTP status code in the response from the backend service matches a specified retry status code, Cloud-native API Gateway retries the request.

      Note

      You can use retry status codes only if retriable-status-codes is specified in the retry condition.

  • The following are the retry conditions for the gRPC protocol:

    • cancelled: If the gRPC status code in the response header from the backend gRPC service is cancelled, Cloud-native API Gateway retries the request.

    • deadline-exceeded: If the gRPC status code in the response header from the backend gRPC service is deadline-exceeded, Cloud-native API Gateway retries the request.

    • internal: If the gRPC status code in the response header from the backend gRPC service is internal, Cloud-native API Gateway retries the request.

    • resource-exhausted: If the gRPC status code in the response header from the backend gRPC service is resource-exhausted, Cloud-native API Gateway retries the request.

    • unavailable: If the gRPC status code in the response header from the backend gRPC service is unavailable, Cloud-native API Gateway retries the request.

Configure a route retry policy

  1. You can configure a retry policy in two ways, depending on how your API is managed:

    API outside an instance

    1. Log in to the Cloud-native API Gateway console. In the navigation pane on the left, click API, and then select a region from the top menu bar.

    2. On the HTTP API page, use the drop-down list at the top to select the target instance. You can select a specific instance or All instances.

    3. In the Routes, click the target route.

    API inside an instance

    1. Log in to the Cloud-native API Gateway console. In the navigation pane on the left, click Instance, and then select a region from the top menu bar.

    2. On the Instance page, click the target gateway instance. In the navigation pane on the left, click API, and then click the target API.

    3. In the Routes, click the target route.

  2. Click the Configure Policy tab. In the Inbound Processing section, click Enable Policy/Plug-in.

  3. Click the Retry card. In the Add Policy: Retry panel, configure the parameters and click Add.

    Note

    After configuring and enabling the retry policy, verify that it works as expected.

    Parameter

    Description

    Enable

    Enables or disables the retry policy for the route.

    • Enabled: The retry policy is active.

    • Disabled: The retry policy is inactive.

    Note

    If this policy is disabled, the gateway uses a default retry configuration. The default number of retries is 2, and the default retry conditions are connect-failure, refused-stream, unavailable, cancelled, and retriable-status-codes.

    Retry Times

    The maximum number of retries for a failed request. The value must be an integer from 0 to 10. A value of 2 or less is recommended.

    Note

    A value of 0 disables retries.

    Retry Condition

    Specifies the conditions that trigger a retry. You can select multiple conditions. For more information, see Retry conditions.

    Retry Status Code

    The HTTP status codes that trigger a retry. You can specify multiple codes.

    Note

    You can configure the Retry Status Code parameter only if retriable-status-codes is selected for Retry Condition.