我在rackspace主机上设置了一个rabbitmq服务器。我已经完成了(python)教程。现在我想做同样的'hello world'教程,但是我没有使用示例脚本连接localhost
,而是想在两台完全不同的机器上运行send.py
和receive.py
。< / p>
我一直在阅读文档,但我不认为我看到它们是如何组合在一起的。我认为我可能需要做的是添加一个用户:
sudo rabbitmqctl add_user xxx yyy
我确定它出现了list_users
$ sudo rabbitmqctl list_users
Listing users ...
guest [administrator]
xxx []
现在我让我的receive.py
在连接到localhost的服务器上运行。但是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
用户?
答案 0 :(得分:1)
根据您的RabbitMQ日志,您似乎忘记为新用户设置适当的权限。
sudo rabbitmqctl set_permissions my_user ".*" ".*" ".*"
如果您使用的是其他虚拟主机,请不要忘记也为该虚拟主机设置权限。
sudo rabbitmqctl set_permissions -p my_virtual_host my_user ".*" ".*" ".*"
您可以在官方文档here中阅读有关这些选项的更多信息。