Guest User

Untitled

a guest
Jul 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import amqplib.client_0_8 as amqp
  4.  
  5. config = {'host':"localhost:5672",'vhost':'...','username':'...','password':'...'}
  6.  
  7. qname = 'python.currency.rates'
  8.  
  9. def process_exchange_rates(msg):
  10. print msg.body
  11. msg.channel.basic_ack(msg.delivery_tag)
  12.  
  13. def main():
  14. conn = amqp.Connection(config['host'], virtual_host=config['vhost'], userid=config['username'], password=config['password'])
  15. ch = conn.channel()
  16. ch.access_request('/data', active=True, read=True)
  17. ch.queue_declare(qname, durable=True, auto_delete=False)
  18. ch.queue_bind(qname, exchange='financial', routing_key='currency.rates')
  19. consumer_tag = ch.basic_consume(qname, callback=process_exchange_rates)
  20.  
  21. print "Subscriber started with consumer tag: {0}".format(consumer_tag)
  22.  
  23. try:
  24. print "Press ^C to stop"
  25. while(True):
  26. ch.wait()
  27. except KeyboardInterrupt:
  28. ch.close()
  29. conn.close()
  30. print "Subscriber stopped"
  31.  
  32. if __name__ == '__main__':
  33. main()
Add Comment
Please, Sign In to add comment