Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import pika
  2.  
  3. connection = pika.BlockingConnection(
  4. pika.ConnectionParameters()
  5. )
  6.  
  7. def channel_queue(channel, *args, **kwargs):
  8. channel.queue_declare(*args, **kwargs)
  9. def decorator(func):
  10. channel.basic_consume(kwargs['queue'], func)
  11. def wrapper(*args, **kwargs):
  12. return func(*args, **kwargs)
  13. return wrapper
  14. return decorator
  15.  
  16. channel = connection.channel()
  17.  
  18. ### Without decorator
  19. '''
  20. channel.queue_declare(queue='queue')
  21. def func(ch, method, properties, body):
  22. print(body)
  23.  
  24. channel.basic_consume('queue', func)
  25. '''
  26.  
  27. ### With decorator
  28.  
  29. @channel_queue(channel, queue='queue')
  30. def func(ch, method, properties, body):
  31. print(body)
  32.  
  33. channel.start_consuming()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement