【问题标题】:Can I get RabbitMq connection id from my Python/kombu client?我可以从我的 Python/kombu 客户端获取 RabbitMq 连接 ID 吗?
【发布时间】:2016-03-17 13:42:56
【问题描述】:

当我运行这个命令时:

rabbitmqctl list_connections pid

我得到如下输出:

<rabbit@my_box.2.1234.0>
<rabbit@my_box.2.1235.0>

有没有办法从我的 Kombu 客户端读取这个 pid?

【问题讨论】:

    标签: python-2.7 rabbitmq kombu


    【解决方案1】:

    RabbitMQ 不会通过 AMQP 暴露这种内部细节。

    您可以使用management plugin and its REST API 获取有关连接的许多信息。这是一个例子:

    // JSON returned by http://localhost:15672/api/connections
    // ...
    {
        "connected_at": 1458292870638,
        "client_properties":
    {   
        "product": "RabbitMQ",
        "copyright": "Copyright (c) 2007-2016 Pivotal Software, Inc.",
        "capabilities":
        {   
            "exchange_exchange_bindings": true,
            "connection.blocked": true,
            "authentication_failure_close": true,
            "basic.nack": true,
            "publisher_confirms": true,
            "consumer_cancel_notify": true
        },
        "information": "Licensed under the MPL. See http://www.rabbitmq.com/",
        "version": "0.0.0",
        "platform": "Java"
    },
    "channel_max": 0,
    "frame_max": 131072,
    "timeout": 60,
    "vhost": "/",
    "user": "guest",
    "protocol": "AMQP 0-9-1",
    "ssl_hash": null,
    "ssl_cipher": null,
    "ssl_key_exchange": null,
    "ssl_protocol": null,
    "auth_mechanism": "PLAIN",
    "peer_cert_validity": null,
    "peer_cert_issuer": null,
    "peer_cert_subject": null,
    "ssl": false,
    "peer_host": "127.0.0.1",
    "host": "127.0.0.1",
    "peer_port": 54872,
    "port": 5672,
    "name": "127.0.0.1:54872 -> 127.0.0.1:5672",
    "node": "rabbit@localhost",
    "type": "network",
    "channels": 1,
    "state": "running",
    "send_pend": 0,
    "send_cnt": 108973,
    "recv_cnt": 99426,
    "recv_oct_details":
    {   
        "rate": 288892.8
    },
    "recv_oct": 5540646,
    "send_oct_details":
        {
            "rate": 1912389.8
        },
        "send_oct": 36669998
    },
    // ...
    

    但是,PID 也不会通过这种机制公开。

    【讨论】:

    • 非常感谢,这有帮助!
    • 出于好奇,您想达到什么目的?例如,您是否需要此 REST 调用的更多信息?
    • 我正在测试我的应用程序如何处理丢失的连接。为此,我需要删除我的连接。目前我通过rabbitmqctl手动删除它。自动化这个测试会很好。为了保持自动化测试环境精益求精,我们希望以绝对最低限度过活,而不是安装额外的工具。
    • 我不知道 Kombu,但如果你能得到源 TCP 端口,那么你可以驱动防火墙阻止连接。我认为这比询问 RabbitMQ 更容易。
    • 我会试一试。谢谢!
    猜你喜欢
    • 2012-04-03
    • 2013-04-06
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 2018-07-13
    • 2022-11-06
    相关资源
    最近更新 更多