Travis Griggs
Travis Griggs

Reputation: 22252

Two different machines talk publicly via rabbitmq?

I've set up a rabbitmq server on rackspace host. I've done the (python) tutorials. Now I want to do same 'hello world' tutorials, but instead of connecting to localhost with the example scripts, I want to run the send.py and receive.py on two totally different machines.

I've been reading through the docs, but I don't think I'm seeing how it all fits together. What I thought I might need to do, is add a user:

sudo rabbitmqctl add_user xxx yyy

I made sure it showed up with a list_users

$ sudo rabbitmqctl list_users
Listing users ...
guest   [administrator]
xxx []

For now I let my receive.py run on the server connecting against localhost. But the send.py, I moved to a Raspberry like Linux SBC and rewrote using amqpstorm:

#!/usr/bin/env python3
import logging
from amqpstorm import Connection, Message

logging.basicConfig(level=logging.DEBUG)

def publisher():
    with Connection('abc.def.com', 'xxx', 'yyy') as connection:
        with connection.channel() as channel:
            channel.queue.declare(queue='hello')
            properties = {
                'content_type': 'text/plain',
                'headers': {'key': 'value'}
            }

            message = Message.create(channel, 'Vennlig Hilsen', properties)
            message.publish('hello')

if __name__ == '__main__':
    publisher()

That creates the following error:

# ./send.py 
DEBUG:amqpstorm.connection:Connection Opening
DEBUG:amqpstorm.channel0:Frame Received: Connection.Start
DEBUG:amqpstorm.channel0:Frame Sent: Connection.StartOk
DEBUG:amqpstorm.channel0:Frame Received: Connection.Tune
DEBUG:amqpstorm.channel0:Frame Sent: Connection.TuneOk
DEBUG:amqpstorm.channel0:Frame Sent: Connection.Open
Traceback (most recent call last):
  File "./xend.py", line 22, in <module>
    publisher()
  File "./xend.py", line 9, in publisher
    with Connection('abc.def.com', 'xxx', 'yay') as connection:
  File "/usr/lib/python3/dist-packages/amqpstorm/connection.py", line 70, in __init__
    self.open()
  File "/usr/lib/python3/dist-packages/amqpstorm/connection.py", line 191, in open
    self._wait_for_connection_state(state=Stateful.OPEN)
  File "/usr/lib/python3/dist-packages/amqpstorm/connection.py", line 314, in _wait_for_connection_state
    raise AMQPConnectionError('Connection timed out')
amqpstorm.exception.AMQPConnectionError: Connection timed out

It spits out the first 6 DEBUG lines pretty quickly, and then stalls with an eventual timeout error of some sort.

Am I even on the right path? Or barking up the wrong tree? Do I need to do more to configure my user (I didn't do anything other than add it)? Is there somewhere I can see additional logging of the server, other than journalctl?

UPDATE

$ tail -f /var/log/rabbitmq/rabbit\@server5.log

=INFO REPORT==== 18-Oct-2016::15:09:28 ===
accepting AMQP connection <0.307.0> (67.158.225.133:32786 -> 23.253.234.130:5672)

=ERROR REPORT==== 18-Oct-2016::15:09:32 ===
closing AMQP connection <0.307.0> (67.158.225.133:32786 -> 23.253.234.130:5672):
{handshake_error,opening,0,
                 {amqp_error,access_refused,
                             "access to vhost '/' refused for user 'xxx'",
                             'connection.open'}}

This tells me that I must need to do something additionally to authorize the xxxuser?

Upvotes: 1

Views: 381

Answers (1)

eandersson
eandersson

Reputation: 26352

Based on your RabbitMQ logs it looks like you forgot to set the appropriate permissions for your new user.

sudo rabbitmqctl set_permissions my_user ".*" ".*" ".*"

If you are using a different virtual host don't forget to set the permissions for that virtual host as well.

sudo rabbitmqctl set_permissions -p my_virtual_host my_user ".*" ".*" ".*"

You can read more about these options in the official documentation here.

Upvotes: 1

Related Questions