Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get detailed log/info about rabbitmq connection action?

Tags:

rabbitmq

I have a python program connecting to a rabbitmq server. When this program starts, it connects well. But when rabbitmq server restarts, my program can not reconnect to it, and leaving error just "Socket closed"(produced by kombu), which is meaningless.

I want to know the detailed info about the connection failure. On the server side, there is nothing useful in the rabbitmq log file either, it just said "connection failed" with no reason given.

I tried the trace plugin(https://www.rabbitmq.com/firehose.html), and found there was no trace info published to amq.rabbitmq.trace exchange when the connection failure happended. I enabled the plugin with:

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

and then i wrote a client to get message from 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()

I also tried to get some debug log from rabbitmq server. I reconfigured rabbitmq.config according to https://www.rabbitmq.com/configure.html, and set log_levels to

{log_levels, [{connection, info}]}

but as a result rabbitmq server failed to start. It seems like the official doc is not for me, my rabbitmq server version is 3.3.5. However

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

or

{log_levels, [connection,debug]}

works, but with this there is no DEBUG info showing in the logs, which i don't know whether it is because the log_levels configuration is not effective or there is just no DEBUG log got printed all the time.

like image 661
apporc Avatar asked Jul 21 '15 09:07

apporc


1 Answers

I know that this answer comes massively late, but for future purveyors, this worked for me:

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

Basically, you just need to wrap the parameters you want to set in whichever module/plugin they belong to.

like image 192
Wesley Avatar answered Oct 12 '22 10:10

Wesley