Commits

Chad Burrus committed 587ff25

tutorial 1

Comments (0)

Files changed (2)

+#!/usr/bin/env python
+import pika
+
+# make connection to RabbitMQ server
+connection = pika.BlockingConnection(pika.ConnectionParameters(
+        host='localhost'))
+channel = connection.channel()
+
+# Prepare the recipient queue -- do this in both places so it doesn't matter which one runs first
+channel.queue_declare(queue='hello')
+
+# Print a handy message
+print ' [*] Waiting for messages. To exit press CTRL+C'
+
+# The thing to do when a message is received
+def callback(ch, method, properties, body):
+    print " [x] Received %r" % (body,)
+
+# Set up the consumer
+channel.basic_consume(callback,
+                      queue='hello',
+                      no_ack=True)
+
+# Start consuming
+channel.start_consuming()
+#!/usr/bin/env python
+import pika
+
+# make connection to RabbitMQ server
+connection = pika.BlockingConnection(pika.ConnectionParameters(
+                 'localhost'))
+channel = connection.channel()
+
+# Prepare the recipient queue -- do this in both places so it doesn't matter which one runs first
+channel.queue_declare(queue='hello')
+
+# Send the message
+channel.basic_publish(exchange='',
+                      routing_key='hello',
+                      body='Hello World!')
+
+# Print a handy message
+print " [x] Sent 'Hello World!'"
+
+# Close up shop, flushing buffers and the like
+connection.close()