如何获得关于 rabbitmq 连接操作的详细信息 log/info?
How to get detailed log/info about rabbitmq connection action?
我有一个 python 程序连接到 rabbitmq 服务器。当这个程序启动时,它连接良好。但是当rabbitmq server重启后,我的程序无法重新连接,只留下错误"Socket closed"(produced by kombu),这是没有意义的。
我想知道连接失败的详细信息。在服务器端,rabbitmq 日志文件中也没有任何有用的内容,它只是说 "connection failed" 没有给出任何理由。
我尝试了trace插件(https://www.rabbitmq.com/firehose.html),发现连接失败时没有trace信息发布到amq.rabbitmq.trace exchange。我启用了插件:
rabbitmq-plugins enable rabbitmq_tracing
systemctl restart rabbitmq-server
rabbitmqctl trace_on
然后我写了一个客户端从 amq.rabbitmq.trace exchange 获取消息:
#!/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]}
有效,但是日志中没有显示 DEBUG 信息,我不知道是因为 log_levels 配置无效还是没有打印所有 DEBUG 日志时间.
我知道这个答案来得太晚了,但对于未来的供应商来说,这对我有用:
[
{rabbit,
[
{log_levels, [{connection, debug}, {channel, debug}]}
]
}
].
基本上,您只需要将要设置的参数包装在它们所属的module/plugin中即可。
我有一个 python 程序连接到 rabbitmq 服务器。当这个程序启动时,它连接良好。但是当rabbitmq server重启后,我的程序无法重新连接,只留下错误"Socket closed"(produced by kombu),这是没有意义的。
我想知道连接失败的详细信息。在服务器端,rabbitmq 日志文件中也没有任何有用的内容,它只是说 "connection failed" 没有给出任何理由。
我尝试了trace插件(https://www.rabbitmq.com/firehose.html),发现连接失败时没有trace信息发布到amq.rabbitmq.trace exchange。我启用了插件:
rabbitmq-plugins enable rabbitmq_tracing
systemctl restart rabbitmq-server
rabbitmqctl trace_on
然后我写了一个客户端从 amq.rabbitmq.trace exchange 获取消息:
#!/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]}
有效,但是日志中没有显示 DEBUG 信息,我不知道是因为 log_levels 配置无效还是没有打印所有 DEBUG 日志时间.
我知道这个答案来得太晚了,但对于未来的供应商来说,这对我有用:
[
{rabbit,
[
{log_levels, [{connection, debug}, {channel, debug}]}
]
}
].
基本上,您只需要将要设置的参数包装在它们所属的module/plugin中即可。