Use Python puka client with RabbitMQ

Send a message to RabbitMQ

  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. sys.path.append("..")
  5.  
  6.  
  7. import puka
  8.  
  9. client = puka.Client("amqp://localhost/")
  10.  
  11. promise = client.connect()
  12. client.wait(promise)
  13.  
  14. promise = client.queue_declare(queue='test')
  15. client.wait(promise)
  16.  
  17. promise = client.basic_publish(exchange='', routing_key='test',
  18. body="Hello world!")
  19. client.wait(promise)
  20.  
  21. print " [*] Message sent"
  22.  
  23. promise = client.queue_declare(queue='test', passive=True)
  24. print " [*] Queue size:", client.wait(promise)['message_count']
  25.  
  26. promise = client.close()
  27. client.wait(promise)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>