两台不同的机器通过 rabbitmq 公开交谈?

Two different machines talk publicly via rabbitmq?

我已经在 rackspace 主机上设置了一个 rabbitmq 服务器。我已经完成了 (python) 教程。现在我想做同样的 'hello world' 教程,但不是使用示例脚本连接到 localhost,我想 运行 send.pyreceive.py 两个完全不同的机器。

我一直在通读文档,但我认为我没有看到它们是如何组合在一起的。我想我可能需要做的是添加一个用户:

sudo rabbitmqctl add_user xxx yyy

我确定它显示了 list_users

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

现在我让我的 receive.py 运行 在服务器上连接本地主机。但是 send.py,我搬到了像 Linux SBC 这样的 Raspberry 并使用 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()

这会产生以下错误:

# ./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

它很快吐出前 6 行 DEBUG 行,然后由于某种最终超时错误而停止。

我走的路对吗?还是找错树了?我是否需要做更多的事情来配置我的用户(除了添加它我什么也没做)?除了 journalctl 之外,还有什么地方可以看到服务器的其他日志记录吗?

更新

$ 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'}}

这告诉我,我必须另外做一些事情来授权 xxx 用户?

根据您的 RabbitMQ 日志,您似乎忘记了为新用户设置适当的权限。

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

如果您使用的是不同的虚拟主机,请不要忘记也为该虚拟主机设置权限。

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

您可以在官方文档中阅读有关这些选项的更多信息 here