36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
from datetime import datetime
|
|
|
|
import pika
|
|
|
|
|
|
DATETIMES=[]
|
|
|
|
|
|
def callback(ch, method, properties, body):
|
|
DATETIMES.append(datetime.now())
|
|
|
|
|
|
try:
|
|
credentials = pika.PlainCredentials("rabbit", "rabbit")
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", credentials=credentials, heartbeat=0, socket_timeout=5))
|
|
channel = connection.channel()
|
|
channel.exchange_declare(exchange="test",exchange_type='direct')
|
|
queue_declare_result = channel.queue_declare(queue='testqueue', exclusive=False)
|
|
queue_name = queue_declare_result.method.queue
|
|
channel.queue_bind(exchange="test",routing_key='test', queue=queue_name)
|
|
channel.basic_qos(prefetch_count=1)
|
|
channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
|
|
channel.start_consuming()
|
|
except KeyboardInterrupt:
|
|
connection.close()
|
|
dt = {}
|
|
for datetime in DATETIMES:
|
|
dts = datetime.strftime("%m/%d/%Y, %H:%M:%S")
|
|
if dts not in dt:
|
|
dt[dts] = 1
|
|
else:
|
|
dt[dts] +=1
|
|
for key in dt:
|
|
print(key,",",dt[key])
|