DAS_2024_1/polevoy_sergey_lab_4/attempt/consumer2.py

25 lines
797 B
Python
Raw Normal View History

import pika
def callback(ch, method, properties, body):
print(f'Consumer 2: получено сообщение. {body.decode()}')
print('Consumer 2 закончил обработку')
ch.basic_ack(method.delivery_tag)
def consume_events_2():
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost', port=5672, credentials=pika.PlainCredentials("superuser", "superpassword")))
channel = connection.channel()
channel.queue_declare(queue='consumer2_queue')
channel.queue_bind(exchange='ml_events', queue='consumer2_queue')
channel.basic_consume(queue='consumer2_queue', on_message_callback=callback)
print('Ожидание сообщения...')
channel.start_consuming()
if __name__ == "__main__":
consume_events_2()