added logging queue
This commit is contained in:
parent
f118e109c2
commit
d060d8e711
8
functions.py
Normal file
8
functions.py
Normal file
@ -0,0 +1,8 @@
|
||||
import pika
|
||||
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password")))
|
||||
channel = connection.channel()
|
||||
|
||||
def log(data):
|
||||
channel.basic_publish(exchange='', routing_key='log', body=data)
|
||||
|
||||
24
log.py
Normal file
24
log.py
Normal file
@ -0,0 +1,24 @@
|
||||
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")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user