Created
February 25, 2014 13:27
-
-
Save squaremo/9208682 to your computer and use it in GitHub Desktop.
RabbitMQ primer RPC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pika | |
import sys | |
import logging | |
logging.basicConfig(level=logging.CRITICAL) | |
params = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F') | |
conn = pika.BlockingConnection(params) | |
ch = conn.channel() | |
ch.queue_declare('taskrabbit') | |
ok = ch.queue_declare(exclusive=True) | |
mailbox = ok.method.queue | |
ch.basic_publish('', 'taskrabbit', sys.argv[1], | |
properties=pika.BasicProperties(reply_to=mailbox)) | |
try: | |
for (f, h, b) in ch.consume(mailbox): | |
print b | |
ch.basic_ack(f.delivery_tag) | |
break | |
except KeyboardInterrupt: | |
pass | |
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pika | |
import sys | |
import logging | |
logging.basicConfig(level=logging.CRITICAL) | |
params = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F') | |
conn = pika.BlockingConnection(params) | |
ch = conn.channel() | |
ch.queue_declare('taskrabbit') | |
try: | |
for (f, h, req) in ch.consume(queue='taskrabbit'): | |
replyto = h.reply_to | |
reply = req.upper() | |
print("Got '%s', responding '%s'", (req, reply)) | |
ch.basic_publish('', replyto, reply) | |
ch.basic_ack(f.delivery_tag) | |
except KeyboardInterrupt: | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment