VirtualHost
https://www.rabbitmq.com/docs/vhosts
RabbitMQ是多租户系统,Virtual host的目的是实现资源的逻辑隔离(物理隔离并非目的),连接、交换、队列、绑定、用户权限、策略和其他一些东西都属于虚拟主机。
与虚拟主机的连接只能在该虚拟主机中的交换、队列、绑定等上进行操作。
两个虚拟主机之间无法直接交换信息,可以:
- 由应用程序牵线搭桥,消费一个虚拟主机的消息然后发布到另一个虚拟主机
- 使用shovlel插件等
# 添加
rabbitmqctl add_vhost qa1
rabbitmqctl add_vhost qa1 --description "QA environment 1" --default-queue-type quorum --tags qa,project-a
# 更新
rabbitmqctl update_vhost_metadata qa1 --description "QA environment for issue 1662" --default-queue-type quorum --tags qa,project-a,qa-1662
# 查询
rabbitmqctl -q --formatter=pretty_table list_vhosts name description tags default_queue_type
# 删除
rabbitmqctl delete_vhost qa1
资源限制
Configuring Max Connection Limit
To limit the total number of concurrent client connections in vhost vhost_name, use the following limit definition:
rabbitmqctl set_vhost_limits -p qa1 '{"max-connections": 256}'
To block client connections to a vhost, set the limit to a zero:
rabbitmqctl set_vhost_limits -p qa1 '{"max-connections": 0}'
To lift the limit, set it to a negative value:
rabbitmqctl set_vhost_limits -p qa1 '{"max-connections": -1}'
Configuring Max Number of Queues
To limit the total number of queues in vhost vhost_name, use the following limit definition:
rabbitmqctl set_vhost_limits -p qa1 '{"max-queues": 1024}'
To lift the limit, set it to a negative value:
rabbitmqctl set_vhost_limits -p qa1 '{"max-queues": -1}'