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.
-
The following are the retry conditions for the HTTP protocol:
-
5xx: If the backend service returns any
5xxresponse, or if a connection is disconnected, reset, or times out during a read operation, Cloud-native API Gateway retries the request.NoteThe
5xxcondition includes theconnect-failureandrefused-streamconditions. -
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_STREAMerror 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.
NoteYou can use retry status codes only if
retriable-status-codesis 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
-
You can configure a retry policy in two ways, depending on how your API is managed:
API outside an instance
-
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.
-
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.
-
In the Routes, click the target route.
API inside an instance
-
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.
-
On the Instance page, click the target gateway instance. In the navigation pane on the left, click API, and then click the target API.
-
In the Routes, click the target route.
-
-
Click the Configure Policy tab. In the Inbound Processing section, click Enable Policy/Plug-in.
-
Click the Retry card. In the Add Policy: Retry panel, configure the parameters and click Add.
NoteAfter 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.
NoteIf 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, andretriable-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.
NoteA 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.
NoteYou can configure the Retry Status Code parameter only if
retriable-status-codesis selected for Retry Condition. -