SHARE
TWEET

Untitled

a guest Jun 25th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top