RabbitMQ消息时间戳

问题描述 投票:0回答:1

你好,我对Timestamp when message was received by RabbitMQ有相同的问题。我下载,安装并启用RabbitMQ时间戳插件。我对如何使用它有点困惑。如果可能的话,我希望在python中有一个例子。

提前谢谢您

rabbitmq timestamp broker
1个回答
0
投票
#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.exchange_declare(exchange='logs', exchange_type='fanout')

result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue

channel.queue_bind(exchange='logs', queue=queue_name)

print(' [*] Waiting for logs. To exit press CTRL+C')

def callback(ch, method, properties, body):
    print(" [x] %r" % body)
    # This will print out all the headers which will include a header by the name of timestamp  and timestamp_in_ms         
    print prop.headers

channel.basic_consume(
    queue=queue_name, on_message_callback=callback, auto_ack=True)

channel.start_consuming()
© www.soinside.com 2019 - 2024. All rights reserved.