description |
---|
This page provides the technical details of the Retry policy |
You can use the retry
policy to replay requests when experiencing backend connection issues or if the response meets a given condition.
If the retry takes too long, relative to the timeout
value, the request stops and returns status code 502
.
{% hint style="info" %} To replay a request with a payload, the Gateway stores it in memory. We recommend you avoid applying it to requests with a large payload. {% endhint %}
Functional and implementation information for the retry
policy is organized into the following sections:
{% hint style="warning" %} This policy can only be applied to v2 APIs. It cannot be applied to v4 message APIs or v4 proxy APIs. {% endhint %}
{% tabs %} {% tab title="HTTP proxy API example" %} Sample policy configuration:
{
"retry": {
"condition": "{#response.status > 500}",
"maxRetries": 3,
"timeout": 1000
}
}
{% endtab %} {% endtabs %}
The phases checked below are supported by the retry
policy:
v2 Phases | Compatible? | v4 Phases | Compatible? |
---|---|---|---|
onRequest | true | onRequest | false |
onResponse | false | onResponse | false |
onRequestContent | false | onMessageRequest | false |
onResponseContent | false | onMessageResponse | false |
The retry
policy can be configured with the following options:
Property | Required | Description | Default | Example |
---|---|---|---|---|
condition | true | Condition to test to determine whether or not to retry the request (supports Expression Language) | - | {#response.status > 500} |
maxRetries | true | Number of retries before failing (502 - Bad Gateway) | 1 | - |
delay | false | Time between each attempt | 0 | - |
timeout | true | Time after which an operation is considered a failure | 1000 | - |
lastResponse | false | Returns the last attempt response, even if it failed regarding the configured condition. In timeout case, 502 is returned. | false | - |
You can enable or disable the policy with policy identifier retry
.
The following is the compatibility matrix for APIM and the retry
policy:
Plugin version | Supported APIM versions |
---|---|
2.x | All |
HTTP status code | Reason |
---|---|
502 |
|
{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-retry/blob/master/CHANGELOG.md" %}