Skip to main content
Version: 3.0

Consumer Group

Consumer Groups are used to extract commonly used Plugin configurations and can be bound directly to a Consumer.

With consumer groups, you can define any number of plugins, e.g. rate limiting and apply them to a set of consumers, instead of managing each consumer individually.

While configuring the same plugin for the same route, only one copy of the configuration is valid.

The example below illustrates how to create a Consumer Group and bind it to a Consumer:

curl http://127.0.0.1:9180/apisix/admin/consumer_groups/company_a -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"limit-count": {
"count": 200,
"time_window": 60,
"rejected_code": 503,
"group": "$consumer_group_id"
}
}
}'
curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"username": "jack",
"plugins": {
"key-auth": {
"key": "auth-one"
}
},
"group_id": "company_a"
}'

When APISIX can't find the Consumer Group with the group_id, the Admin API is terminated with a status code of 400.

If a Consumer already has the plugins field configured, the plugins in the Consumer Group will effectively be merged into it. The same plugin in the Consumer Group will not override the one configured directly in the Consumer.

For example, if we configure a Consumer Group as shown below:

{
"id": "bar",
"plugins": {
"response-rewrite": {
"body": "hello"
}
}
}

To a Consumer as shown below.

{
"username": "foo",
"group_id": "bar",
"plugins": {
"basic-auth": {
"username": "foo",
"password": "bar"
},
"response-rewrite": {
"body": "world"
}
}
}

Then the body in response-rewrite keeps world.