このページは、まだ日本語ではご利用いただけません。翻訳中です。
With consumer groups, you can define rate limiting tiers and apply them to subsets of application consumers.
You can define consumer groups as tiers, for example:
- A gold tier consumer group with 1000 requests per minute
- A silver tier consumer group with 10 requests per second
- A bronze tier consumer group with 6 requests per second
Consumers that are not in a consumer group default to the Rate Limiting advanced plugin’s configuration, so you can define tier groups for some users and have a default behavior for consumers without groups.
To use consumer groups for rate limiting, you need to:
- Create one or more consumer groups
- Create consumers
- Assign consumers to groups
Create rate limiting tiers
-
Create a consumer group named
Gold
:curl -i -X POST http://localhost:8001/consumer_groups \ --data name=Gold
Response:
{ "created_at": 1638915521, "id": "8a4bba3c-7f82-45f0-8121-ed4d2847c4a4", "name": "Gold", "tags": null }
-
Create a consumer,
Amal
:curl -i -X POST http://localhost:8001/consumers \ --data username=Amal
Response:
{ "created_at": 1638915577, "custom_id": null, "id": "8089a0e6-1d31-4e00-bf51-5b902899b4cb", "tags": null, "type": 0, "username": "Amal", "username_lower": "amal" }
-
Add
Amal
to theGold
consumer group:curl -i -X POST http://localhost:8001/consumer_groups/Gold/consumers \ --data consumer=Amal
Response:
{ "consumer_group": { "created_at": 1638915521, "id": "8a4bba3c-7f82-45f0-8121-ed4d2847c4a4", "name": "Gold", "tags": null }, "consumers": [ { "created_at": 1638915577, "id": "8089a0e6-1d31-4e00-bf51-5b902899b4cb", "type": 0, "username": "Amal", "username_lower": "amal" } ] }
-
Enable the plugin on the consumer group:
curl -i -X POST http://localhost:8001/consumer_groups/gold/plugins/ \ --data name=rate-limiting-advanced \ --data config.limit=5 \ --data config.window_size=30 \ --data config.window_type=sliding \ --data config.retry_after_jitter_max=0 \
This configuration sets the rate limit to five requests (
config.limit
) for every 30 seconds (config.window_size
).