29 lines
775 B
Python
29 lines
775 B
Python
|
import pika
|
||
|
import time
|
||
|
from publisher import EXCHANGE
|
||
|
|
||
|
QUEUE = 'consumer_1_queue'
|
||
|
|
||
|
def callback_1(ch, method, properties, body):
|
||
|
print(f'[x] CONSUMER 1: GET. {body.decode()}')
|
||
|
# Ожидаем некоторое время
|
||
|
time.sleep(3)
|
||
|
print('[!] CONSUMER 1 OFF')
|
||
|
|
||
|
|
||
|
def consume(callback, queue, exchange):
|
||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
||
|
channel = connection.channel()
|
||
|
|
||
|
channel.queue_declare(queue=queue)
|
||
|
channel.queue_bind(exchange=exchange, queue=queue)
|
||
|
|
||
|
channel.basic_consume(queue=queue, on_message_callback=callback, auto_ack=True)
|
||
|
|
||
|
print('[^] WAITING')
|
||
|
channel.start_consuming()
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
consume(callback=callback_1, queue=QUEUE, exchange=EXCHANGE)
|