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 / 的權限

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章