RabbitMQ vhost权限问题

RabbitMQ vhost权限问题

在整合spring boot和RabbitMQ时,需要配置RabbitMQ,由于新手第一次使用,因此vhost的权限并未设置,会遇到如下问题
Channel shutdown: channel error; protocol method: #method<channel.close>(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 / 的权限

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值