Per-user Resource Limits
Overview
Similarly to per-virtual host resource limits, it is possible to limit how many connections and channels a specific user can open.
These limits can be used as guard rails in environments where applications cannot be trusted and monitored in detail, for example, when RabbitMQ clusters are offered as a service.
The limits can be configured using CLI tools or the HTTP API.
Maximum Number of Connections
To limit how many connection a user can open, set the max-connections
limit to
a positive integer:
- rabbitmqctl with bash
- rabbitmqadmin with bash
- rabbitmqctl with PowerShell
- rabbitmqadmin with PowerShell
- HTTP API
rabbitmqctl set_user_limits user1 '{"max-connections": 10}'
rabbitmqadmin user_limits declare --user user1 --name max-connections --value 10
rabbitmqctl.bat set_user_limits user1 "{""max-connections"": 10}"
rabbitmqadmin.exe user_limits declare --user user1 --name max-connections --value 10
Use the PUT /api/user-limits/{username}/{limit}
endpoint with a request body like this:
{"value": 20}
Here is an example that uses curl
:
curl -v -u guest:guest -X PUT http://localhost:15672/api/user-limits/user1/max-connections \
-H "content-type: application/json" \
-d @- <<EOF
{
"value": 20
}
EOF
Maximum Number of Channels
To limit how many channels, in total, a user can open, set the max-channels
limit to
a positive integer:
- rabbitmqctl with bash
- rabbitmqadmin with bash
- rabbitmqctl with PowerShell
- rabbitmqadmin with PowerShell
- HTTP API
rabbitmqctl set_user_limits guest '{"max-connections": 10, "max-channels": 20}'
rabbitmqadmin user_limits declare --user guest --name max-channels --value 20
rabbitmqctl.bat set_user_limits guest "{""max-connections"": 10, ""max-channels"": 20}"
rabbitmqadmin.exe user_limits declare --user guest --name max-channels --value 20
Use the PUT /api/user-limits/{username}/{limit}
endpoint with a request body like this:
{"value": 20}
Here is an example that uses curl
to set a limit for user user1
:
curl -v -u guest:guest -X PUT http://localhost:15672/api/user-limits/user1/max-channels \
-H "content-type: application/json" \
-d @- <<EOF
{
"value": 20
}
EOF
The limit is applied to the total number of channels across all connections opened by the user. Therefore, it must be equal or greater than that the aforementioned maximum connection limit.
Listing User Limits
To list limits for a specific user:
- rabbitmqctl with bash
- rabbitmqadmin with bash
- rabbitmqctl with PowerShell
- rabbitmqadmin with PowerShell
- HTTP API
rabbitmqctl list_user_limits user1
rabbitmqadmin user_limits list --user user1
rabbitmqctl.bat list_user_limits user1
rabbitmqadmin.exe user_limits list --user user1
curl -u guest:guest -X GET http://localhost:15672/api/user-limits/user1
Clearing User Limits
To clear limits for a user, use CLI tools or the HTTP API.
- rabbitmqctl with bash
- rabbitmqadmin with bash
- rabbitmqctl with PowerShell
- rabbitmqadmin with PowerShell
- HTTP API
# clears the maximum number of connections limit
rabbitmqctl clear_user_limits user1 'max-connections'
# clears the maximum number of channels limit
rabbitmqctl clear_user_limits user1 'max-channels'
# clears all limits in a single operation
rabbitmqctl clear_user_limits user1 all
# clears the maximum number of connections limit
rabbitmqadmin user_limits delete --user user1 --name max-connections
# clears the maximum number of channels limit
rabbitmqadmin user_limits delete --user user1 --name max-channels
# clears the maximum number of connections limit
rabbitmqctl.bat clear_user_limits user1 "max-connections"
# clears the maximum number of channels limit
rabbitmqctl.bat clear_user_limits user1 "max-channels"
# clears all limits in a single operation
rabbitmqctl.bat clear_user_limits user1 all
# clears the maximum number of connections limit
rabbitmqadmin.exe user_limits delete --user user1 --name max-connections
# clears the maximum number of channels limit
rabbitmqadmin.exe user_limits delete --user user1 --name max-channels
Use the DELETE /api/user-limits/{username}/{limit}
endpoint without a request body.
Here is an example that uses curl
to clear all limits of user user1
:
curl -v -u guest:guest -X DELETE http://localhost:15672/api/user-limits/user1/max-channels
curl -v -u guest:guest -X DELETE http://localhost:15672/api/user-limits/user1/max-connections