我是 RabbitMQ 新手。我安装了v3.7.7。深入研究以下内容,我已用尽任何其他权限来获得通行证 this error .
我在本地安装了 RabbitMQ,创建了一个接收器和一个客户端来测试。我正在使用默认交换,并且能够读取和写入我通过 C# 代码创建的队列。我在远程计算机上安装了 RabbitMQ 并尝试了相同的操作,但无法让接收器或写入执行更多操作连接到服务器。所以我知道授权是正确的,但似乎在某处缺少权限。
在远程服务器上,这是我用于测试的命令:
rabbitmqctl add_vhost /els
rabbitmqctl delete_user guest
rabbitmqctl add_user gavin gavin
rabbitmqctl authenticate_user gavin gavin
rabbitmqctl set_permissions -p /els gavin "^gavin-.*" ".*" ".*"
当我执行以下命令时:
QueueDeclareOk ok = _channel.QueueDeclare(queue.ToString(), durable, exclusive, autoDelete, null);
我收到此错误:
The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=403, text="ACCESS_REFUSED - access to queue 'Ping' in vhost '/els' refused for user 'gavin'", classId=50, methodId=10, cause=
在本地,即使 Ping 队列尚不存在,它也会在我的以下 BasicConsume() 方法上创建它。我错过了什么吗?有没有办法在访问这些队列之前创建这些队列,或者我需要通过 RabbitMQ 的命令添加队列还是什么?
我的监听器代码,它位于一个被多次调用的函数中,每个队列一个:
//if queue exists or not, this will return 0 if there are no messages in the queue.
QueueDeclareOk ok = _channel.QueueDeclare(
queue.ToString(),
durable,
exclusive,
autoDelete,
null);
//returns the number of messages in Ready state in the queue
if (ok.MessageCount > 0)
Console.WriteLine($" ## {queue.ToString()} has {ok.MessageCount} messages in it's queue. ##");
//create a call back consumer
AsyncEventingBasicConsumer consumer = new AsyncEventingBasicConsumer(_channel);
//method to bind callback to.
consumer.Received += Consumer_Received;
//consume existing and future messages
string consumerTag = _channel.BasicConsume(queue: queue.ToString(),
autoAck: autoAck,
consumer: consumer);
//add to dictionary so it can be cancel
_consumerTag.Add(queue, consumerTag);
最佳答案
通过以下方法解决了这个问题:
rabbitmqctl clear_permissions -p /els gavin
rabbitmqctl set_permissions -p /els gavin ".*" ".*" ".*"
关于c# - 代码=403,ACCESS_REFUSED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51387105/