首页 文章

使用RabbitMQ重置连接

提问于
浏览
0

直升机,

我是兔子的新手 . 我试图 Build 一个rabbitmq路由器,并使用鼠标在python中向他发送HelloWorld .

在终端我做sudo rabbitmq-server启动 . 我可以输入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,但我已经配置好了 . 这是一个snipet:

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 . 任何的想法?

1 回答

  • 1

    http://www.rabbitmq.com/man/rabbitmqctl.1.man.html

    你必须添加一个rabbitmq用户,

    rabbitmqctl add_user username password
    

    控制你的用户

    rabbitmqctl list_users
    

    添加vhost

    rabbitmqctl add_vhost test
    

    用户vhost权限

    rabbitmqctl set_permissions -p / username ".*"  ".*" ".*"
    

相关问题