Files
hse-2026/materials/05-indirect-comm/seminar/topic/consumer_all/consumer_all.py
T

24 lines
736 B
Python
Raw Normal View History

2026-10-07 20:52:26 +03:00
import pika
if __name__ == '__main__':
connection = pika.BlockingConnection(pika.ConnectionParameters(host='rabbitmq', port=5672))
channel = connection.channel()
channel.exchange_declare(exchange='topic_logs', exchange_type='topic')
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='topic_logs', queue=queue_name, routing_key='#')
print(' [*] Waiting for logs.')
def callback(ch, method, properties, body):
print(f" [x] {method.routing_key}:{body.decode()}")
ch.basic_ack(delivery_tag=method.delivery_tag)
channel.basic_consume(queue=queue_name, on_message_callback=callback)
channel.start_consuming()