Advertisement
Guest User

Untitled

a guest
Jun 5th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import pika
  3. import time
  4.  
  5. connection = pika.BlockingConnection(pika.ConnectionParameters(
  6.         host='localhost'))
  7. channel = connection.channel()
  8.  
  9. channel.exchange_declare(exchange='tasks', type='direct')
  10. channel.queue_declare(queue='task_queue', durable=True)
  11. print ' [*] Waiting for messages. To exit press CTRL+C'
  12.  
  13. def callback(ch, method, properties, body):
  14.     print " [x] Received %r" % (body,)
  15.     time.sleep( body.count('.') )
  16.     print " [x] Done"
  17.     ch.basic_ack(delivery_tag = method.delivery_tag)
  18.  
  19. channel.basic_qos(prefetch_count=1)
  20. channel.queue_bind(exchange='tasks', queue='task_queue', routing_key='task_queue')
  21. channel.basic_consume(callback,
  22.                       queue='task_queue')
  23.  
  24. channel.start_consuming()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement