The key-rate-limit plug-in throttles requests based on specific key values obtained from URL parameters or HTTP request headers.
Plug-in type
Throttling plug-in.
Fields
|
Field |
Data type |
Required |
Default value |
Description |
|
limit_by_header |
string |
No You must configure limit_by_header or limit_by_param. |
- |
The HTTP request header that provides the throttling key value. |
|
limit_by_param |
string |
No You must configure limit_by_header or limit_by_param. |
- |
The URL parameter that provides the throttling key value. |
|
limit_keys |
array of object |
Yes |
- |
The rate limiting rules for specific key values. |
Fields in the limit_keys object:
|
Configuration item |
Data type |
Required |
Default value |
Description |
|
key |
string |
Yes |
- |
The value to match against incoming requests. |
|
query_per_second |
number |
No You must configure query_per_second, query_per_minute, query_per_hour, or query_per_day. |
- |
The maximum number of requests allowed per second. |
|
query_per_minute |
number |
No You must configure query_per_second, query_per_minute, query_per_hour, or query_per_day. |
- |
The maximum number of requests allowed per minute. |
|
query_per_hour |
number |
No You must configure query_per_second, query_per_minute, query_per_hour, or query_per_day. |
- |
The maximum number of requests allowed per hour. |
|
query_per_day |
number |
No You must configure query_per_second, query_per_minute, query_per_hour, or query_per_day. |
- |
The maximum number of requests allowed per day. |
Examples
-
Throttle requests by the key value from the request header x-ca-key.
limit_by_header: x-ca-key limit_keys: - key: 102234 query_per_second: 10 - key: 308239 query_per_hour: 10 -
Throttle requests by the key value from the request parameter apikey.
limit_by_param: apikey limit_keys: - key: 9a342114-ba8a-11ec-b1bf-00163e1250b5 query_per_second: 10 - key: a6a6d7f2-ba8a-11ec-bec2-00163e1250b5 query_per_minute: 100 -
Enable throttling for specific routes or domain names.
Apply the following plug-in configurations to the
route-aandroute-broutes:limit_by_header: x-ca-key limit_keys: - key: 102234 query_per_second: 10Apply the following plug-in configuration to the
*.example.comandtest.comdomain names:limit_by_header: x-ca-key limit_keys: - key: 102234 query_per_second: 100Note-
route-aandroute-brefer to routes specified when creating gateway routes. If a request matches one of these routes, the corresponding rules take effect. -
*.example.comandtest.commatch request domain names. If a request matches one of these domains, the corresponding rules take effect. -
Rules take effect in sequence. If the first rule is matched, subsequent rules are ignored.
-