Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import amqplib.client_0_8 as amqp
- config = {'host':"localhost:5672",'vhost':'...','username':'...','password':'...'}
- qname = 'python.currency.rates'
- def process_exchange_rates(msg):
- print msg.body
- msg.channel.basic_ack(msg.delivery_tag)
- def main():
- conn = amqp.Connection(config['host'], virtual_host=config['vhost'], userid=config['username'], password=config['password'])
- ch = conn.channel()
- ch.access_request('/data', active=True, read=True)
- ch.queue_declare(qname, durable=True, auto_delete=False)
- ch.queue_bind(qname, exchange='financial', routing_key='currency.rates')
- consumer_tag = ch.basic_consume(qname, callback=process_exchange_rates)
- print "Subscriber started with consumer tag: {0}".format(consumer_tag)
- try:
- print "Press ^C to stop"
- while(True):
- ch.wait()
- except KeyboardInterrupt:
- ch.close()
- conn.close()
- print "Subscriber stopped"
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment