Skip to content

Latest commit

 

History

History
96 lines (69 loc) · 3.47 KB

File metadata and controls

96 lines (69 loc) · 3.47 KB
description
This page provides the technical details of the Latency policy

Latency

Overview

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:

Examples

{% 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 %}

Configuration

Phases

The phases checked below are supported by the latency policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsefalseonResponsefalse
onRequestContentfalseonMessageRequesttrue
onResponseContentfalseonMessageResponsetrue

Options

You can configure the latency policy with the following options:

PropertyRequiredDescriptionTypeDefault
timefalseTime to wait (ms)integer100
timeUnitfalseTime unit ( "MILLISECONDS" or "SECONDS")string"MILLISECONDS"

Compatibility matrix

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+

Errors

HTTP status codeMessage
500Server error

Changelogs

{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-latency/blob/master/CHANGELOG.md" %}