Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pika
- connection = pika.BlockingConnection(
- pika.ConnectionParameters()
- )
- def channel_queue(channel, *args, **kwargs):
- channel.queue_declare(*args, **kwargs)
- def decorator(func):
- channel.basic_consume(kwargs['queue'], func)
- def wrapper(*args, **kwargs):
- return func(*args, **kwargs)
- return wrapper
- return decorator
- channel = connection.channel()
- ### Without decorator
- '''
- channel.queue_declare(queue='queue')
- def func(ch, method, properties, body):
- print(body)
- channel.basic_consume('queue', func)
- '''
- ### With decorator
- @channel_queue(channel, queue='queue')
- def func(ch, method, properties, body):
- print(body)
- channel.start_consuming()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement