Consumer
It has the highest priority: Consumer > Route > Plugin Config > Service.
But this level of depth can be insufficient on some occasions.
An API gateway should know who the consumer of the API is to configure different rules for different consumers. This is where the Consumer construct comes in APISIX.
The fields for defining a Consumer are defined as below.
- The first step is Authentication. This is achieved by Authentication Plugins like key-auth and .
- After authenticating, you can obtain the
id
of the Consumer. Thisid
will be the unique identifier of a Consumer. - The configurations like Plugins and Upstream bound to the Consumer are then executed.
Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.
Refer to the documentation for the key-auth authentication Plugin to further understand the concept of a Consumer.
note
For more information about the Consumer object, you can refer to the Admin API Consumer object resource introduction.
The example below shows how you can enable a Plugin for a specific Consumer.
Send a test request, the first two return to normal, did not reach the speed limit threshold.
The third test returns
503
and the request is restricted.HTTP/1.1 503 Service Temporarily Unavailable
...
We can use the consumer-restriction Plugin to restrict our user “Jack” from accessing the API.
Add Jack to the blacklist.
-