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