【发布时间】: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