Permalink
Browse files

Show a consumer in the README

  • Loading branch information...
1 parent 3ecaad1 commit ac3dd9b80e13c2ce6a746c724478b5ee7808b048 Gavin M. Roy committed Nov 12, 2012
Showing with 23 additions and 2 deletions.
  1. +23 −2 README.md
View
@@ -15,19 +15,40 @@ to stay fairly independent of the underlying network support library.
make adapting it to a new environment as simple as possible.
## Documentation
-Pika's documentation is now at http://pika.github.com/
+Pika's documentation is now at https://pika.readthedocs.org
## Example
Here is the most simple example of use, sending a message with the BlockingConnection adapter:
import pika
- connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
+ connection = pika.BlockingConnection()
channel = connection.channel()
channel.basic_publish(exchange='example',
routing_key='test',
body='Test Message')
connection.close()
+And an example of writing a blocking consumer:
+
+ import pika
+ connection = pika.BlockingConnection()
+ channel = connection.channel()
+
+ for method_frame, properties, body in channel.consume('test'):
+
+ # Display the message parts and ack the message
+ print method_frame, properties, body
+ channel.basic_ack(method_frame.delivery_tag)
+
+ # Escape out of the loop after 10 messages
+ if method_frame.delivery_tag == 10:
+ break
+
+ # Cancel the consumer and return any pending messages
+ requeued_messages = channel.cancel()
+ print 'Requeued %i messages' % requeued_messages
+ connection.close()
+
## Pika provides the following adapters
* AsyncoreConnection - based off the standard Python library asyncore
* BlockingConnection - enables blocking, synchronous operation on top of

0 comments on commit ac3dd9b

Please sign in to comment.