Skip to content

Commit

Permalink
add t/node/consumer-group.t and consumer-group.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kingluo committed Sep 29, 2022
1 parent a4aeb32 commit e36abeb
Show file tree
Hide file tree
Showing 2 changed files with 413 additions and 0 deletions.
101 changes: 101 additions & 0 deletions docs/en/latest/terminology/consumer-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Consumer Group
keywords:
- API gateway
- Apache APISIX
- Consumer Group
description: Consumer Group in Apache APISIX.
---

<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

Consumer Groups are used to extract commonly used [Plugin](./plugin.md) configurations and can be bound directly to a [Consumer](./consumer.md).

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 order of precedence is `Consumer` > `Consumer Group` > `Route` > `plugin_config` > `Service`.

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

```shell
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"
}
}
}'
```

```shell
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 to it. The same plugin in the Consumer Group will not override the ones 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`.
Loading

0 comments on commit e36abeb

Please sign in to comment.