RabbitMQ vhost权限问题

RabbitMQ vhost权限问题

在整合spring boot和RabbitMQ时,需要配置RabbitMQ,由于新手第一次使用,因此vhost的权限并未设置,会遇到如下问题
Channel shutdown: channel error; protocol method: #method(reply-code=403, reply-text=ACCESS_REFUSED - access to queue ‘queue’ in vhost ‘/’ refused for user ‘rabbit’, class-id=60, method-id=20)

我的配置为:
#RabbitMQ
spring.rabbitmq.host=myhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=rabbit
spring.rabbitmq.password=rabbit
spring.rabbitmq.virtual-host=/
spring.rabbitmq.listener.simple.concurrency=10
spring.rabbitmq.listener.simple.max-concurrency=10
spring.rabbitmq.listener.simple.prefetch=1
spring.rabbitmq.listener.simple.auto-startup=true
spring.rabbitmq.listener.simple.default-requeue-rejected=true
spring.rabbitmq.template.retry.enabled=true
spring.rabbitmq.template.retry.initial-interval=1000
spring.rabbitmq.template.retry.max-attempts=3
spring.rabbitmq.template.retry.max-interval=10000
spring.rabbitmq.template.retry.multiplier=1.0

查阅官方文档可以发现, RabbitMQ支持使用命令set_permissions来设置vhost的权限,附上官方解释作为参考
set_permissions [-p vhost] user conf write read
vhost
The name of the virtual host to which to grant the user access, defaulting to “/”.
user
The name of the user to grant access to the specified virtual host.
conf
A regular expression matching resource names for which the user is granted configure permissions.
write
A regular expression matching resource names for which the user is granted write permissions.
read
A regular expression matching resource names for which the user is granted read permissions.
Sets user permissions.
For example, this command instructs the RabbitMQ broker to grant the user named “tonyg” access to the virtual host called “/myvhost”, with configure permissions on all resources whose names starts with “tonyg-”, and write and read permissions on all resources:

rabbitmqctl set_permissions -p /myvhost tonyg “^tonyg-.*” “.*” “.*”

从上面的解释可以知道我们需要为用户rabbit添加权限来进行对vhost "/"的操作,因此这个案例可以使用如下命令解决:

rabbitmqctl set_permissions -p / rabbit ".*" ".*" ".*"

此命令给与用户rabbit所有操作vhost / 的权限

你可能感兴趣的:(Linux,MessageQueue)