RabbitMQ Declare Exchange from Terminal - Access refused: /api/exchanges/

James Oravec picture James Oravec · Oct 1, 2014 · Viewed 19.1k times · Source

I'm using rabbitmq to handle messages between my databases for an enterprise application I work on. As part of the process, I'm trying to help automate the setup of the servers (e.g. script it). In this process, I've tried to use rabbitmqadmin to declare exchanges from the command prompt. I have 2 different servers running CentOS 5.x and CentOS 6.x and both are having the same issue.

So far I declared an administrator user and set its password, then I set its tag to be of the administrator tag, then I ensure it has permissions to the vhosts. After that I try to declare the exchange, with user and password specified and it fails.

rabbitmqctl add_user administrator password
rabbitmqctl set_user_tags administrator administrator
rabbitmqctl set_permissions -p / administrator ".*" ".*" ".*"
rabbitmqctl add_vhost vhostFoo
rabbitmqctl set_permissions -p vhostFoo administrator ".*" ".*" ".*"
rabbitmqadmin -u administrator -p password declare exchange --vhost=vhostFoo name=exchangeNew type=direct

For the CentOS 5.x box I have to use python26 rabbitmqadmin instead of just rabbitmqadmin, but get the same result.

The last command results in:

*** Access refused: /api/exchanges/vhostFoo/exchangeNew

Both my CentOS 5.x and Cent 6.x boxes are running rabbitmq 3.3.5. Any thoughts on what I'm missing or thoughts on how I can get more info on what's wrong (e.g. error log file or way to get more verbose output)?

Answer

James Oravec picture James Oravec · Oct 1, 2014

I figured out my issue and wanted to post the answer in case someone else comes across the same issue. I checked out my /var/log/rabbitmq/ and the last bit showed access to my vhostFoo was refused for user 'guest'. Based on this, it made me think that my order of params was incorrect, which it looks to be the case. I used the following and it worked fine:

rabbitmqadmin declare exchange --vhost=vhostFoo name=exchangeNew type=direct -u administrator -p password