直升机,
我真的是rabbitmq的新手。我试图建立一个rabbitmq路由器并使用pika在python中向他发送一个HelloWorld。
在终端中,我执行 sudo rabbitmq-server start。我可以输入 localhost:15672。但是当我尝试连接到 localhost:5672 时出现“AMQP”一秒钟然后“连接已重置”。
执行 sudo rabbitmqctl list_connections 时,我的连接没有出现。当做 netstat -tapnl | grep 5672 看起来是这样的:
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:5672 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN -
我的 python 给出了错误 ProbableAccessDeniedError,但我认为我已经配置好了。这是一个片段:
import pika
from pika.exceptions import ProbableAccessDeniedError
from pika.exceptions import ProbableAuthenticationError
if __name__ == '__main__':
credentials = pika.PlainCredentials('name', 'pass)
# change the ip in here!
parameters = pika.ConnectionParameters(
host='localhost', port=5672, vhost='test', credentials=credentials)
try:
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello World!')
print(" [x] Sent 'Hello World!'")
except ProbableAuthenticationError:
print("Authetication Error")
except ProbableAccessDeniedError:
print("Authetication Denied")
finally:
if channel:
channel.close()
if connection:
connection.close()
这是我的rabbitmq.config:
[
{rabbit, [
% Network Connectivity
% ====================
{tcp_listeners,[{"127.0.0.1",5672}]},
{num_tcp_acceptors, 5},
{handshake_timeout, 10000},
% Default User / VHost
% ====================
{default_vhost, <<"test">>},
{default_user, <<"name">>},
{default_pass, <<"pass">>},
{default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
{loopback_users, []}
]}
].
所以我猜这个问题是因为localhost:5672。任何想法?