description |
---|
This page provides the technical details of the Latency policy |
You can use the latency
policy to add latency to either the request or the response. For example, if you configure the policy on the request with a latency of 100ms, the Gateway waits 100ms before routing the request to the backend service.
This policy is particularly useful in two scenarios:
- Testing: adding latency allows you to test client applications when APIs are slow to respond.
- Monetization: a longer latency can be added to free plans to encourage clients to move to a better (or paid) plan.
Functional and implementation information for the latency
policy is organized into the following sections:
{% hint style="warning" %} This policy can be applied to v2 APIs, v4 HTTP proxy APIs, and v4 message APIs. It cannot be applied to v4 TCP proxy APIs. {% endhint %}
{% tabs %} {% tab title="HTTP proxy API example" %} Example policy configuration for a proxy API:
{
"name": "Latency policy",
"description": "",
"enabled": true,
"policy": "latency",
"configuration": {
"time": 2,
"timeUnit": "SECONDS"
}
}
{% endtab %}
{% tab title="Message API example" %} Example subscription configuration for a message API:
{
"name": "Latency policy",
"description": "",
"enabled": true,
"policy": "latency",
"configuration": {
"time": 2,
"timeUnit": "SECONDS"
}
}
{% endtab %} {% endtabs %}
The phases checked below are supported by the latency
policy:
v2 Phases | Compatible? | v4 Phases | Compatible? |
---|---|---|---|
onRequest | true | onRequest | true |
onResponse | false | onResponse | false |
onRequestContent | false | onMessageRequest | true |
onResponseContent | false | onMessageResponse | true |
You can configure the latency
policy with the following options:
Property | Required | Description | Type | Default |
---|---|---|---|---|
time | false | Time to wait (ms ) | integer | 100 |
timeUnit | false | Time unit ( "MILLISECONDS" or "SECONDS" ) | string | "MILLISECONDS" |
The following is the compatibility matrix for APIM and the latency
policy.
Plugin version | APIM version |
---|---|
Up to 1.3.x | Up to 3.9.x |
1.4.x | Up to 3.20 |
2.x | 4.x+ |
HTTP status code | Message |
---|---|
500 | Server error |
{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-latency/blob/master/CHANGELOG.md" %}