【问题标题】:How to get detailed log/info about rabbitmq connection action?如何获取有关 rabbitmq 连接操作的详细日志/信息?
【发布时间】:2015-10-10 15:37:55
【问题描述】:

我有一个 python 程序连接到 rabbitmq 服务器。当这个程序启动时,它连接良好。但是当rabbitmq服务器重新启动时,我的程序无法重新连接它,并留下错误只是“Socket closed”(由kombu产生),这是没有意义的。

我想知道连接失败的详细信息。在服务器端,rabbitmq 日志文件中也没有任何用处,它只是说“连接失败”,没有给出任何原因。

我尝试了跟踪插件(https://www.rabbitmq.com/firehose.html),发现连接失败时没有发布到 amq.rabbitmq.trace 交换的跟踪信息。我启用了插件:

rabbitmq-plugins enable rabbitmq_tracing
systemctl restart rabbitmq-server
rabbitmqctl trace_on

然后我写了一个客户端从 amq.rabbitmq.trace 交换中获取消息:

#!/bin/env python
from kombu.connection import BrokerConnection
from kombu.messaging import Exchange, Queue, Consumer, Producer

def on_message(self, body, message):
    print("RECEIVED MESSAGE: %r" % (body, ))
    message.ack()

def main():
    conn = BrokerConnection('amqp://admin:pass@localhost:5672//')
    channel = conn.channel()
    queue = Queue('debug', channel=channel,durable=False)
    queue.bind_to(exchange='amq.rabbitmq.trace', routing_key='publish.amq.rabbitmq.trace')
    consumer = Consumer(channel, queue)
    consumer.register_callback(on_message)
    consumer.consume()
    while True:
        conn.drain_events()

if __name__ == '__main__':
    main()

我还尝试从 rabbitmq 服务器获取一些调试日志。我根据https://www.rabbitmq.com/configure.html重新配置了rabbitmq.config,并设置 log_levels 到

{log_levels, [{connection, info}]}

但结果rabbitmq服务器无法启动。好像官方文档不适合我,我的rabbitmq服务器版本是3.3.5。不过

{log_levels, [connection,debug,info,error]}

{log_levels, [connection,debug]}

有效,但是日志中没有显示调试信息,我不知道是因为log_levels配置无效还是一直没有打印调试日志。

【问题讨论】:

    标签: rabbitmq


    【解决方案1】:

    我知道这个答案来得太晚了,但对于未来的供应商来说,这对我有用:

    [
      {rabbit,
        [
          {log_levels, [{connection, debug}, {channel, debug}]}
        ]
      }
    ].
    

    基本上,您只需将要设置的参数包装在它们所属的任何模块/插件中即可。

    【讨论】:

    • 你知道如何从 rabbitmq 发送日志到 syslog 吗?
    • @Luv33preet 看看this 的系统日志
    猜你喜欢
    • 2014-07-24
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多