-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add t/node/consumer-group.t and consumer-group.md
- Loading branch information
Showing
2 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
Oops, something went wrong.