import pika connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password"))) channel = connection.channel() channel.queue_declare(queue='log') def log(ch, method, properties, body): try: data = body.decode() except UnicodeDecodeError: data = body print(data) channel.basic_consume(queue='log', on_message_callback=log, auto_ack=True) try: print("Opening logs") channel.start_consuming() except KeyboardInterrupt: channel.stop_consuming() channel.close() print("Closing logs")