23 lines
544 B
Python
23 lines
544 B
Python
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:
|
|
channel.start_consuming()
|
|
except KeyboardInterrupt:
|
|
channel.stop_consuming()
|
|
channel.close()
|
|
|