22 lines
775 B
Python
22 lines
775 B
Python
import pika
|
|
|
|
queue_name = 'second_queue'
|
|
exchange = 'logs'
|
|
|
|
|
|
def callback(ch, method, properties, body):
|
|
print(f" Consumer_2: было получено сообщение {body.decode()}")
|
|
print(f" Consumer_2: было обработано сообщение")
|
|
ch.basic_ack(delivery_tag=method.delivery_tag)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
|
channel = connection.channel()
|
|
try:
|
|
channel.queue_declare(queue=queue_name) #queue
|
|
channel.queue_bind(exchange=exchange, queue=queue_name) #binding
|
|
channel.basic_consume(queue=queue_name, on_message_callback=callback)
|
|
channel.start_consuming()
|
|
except KeyboardInterrupt:
|
|
connection.close() |