Created
February 26, 2014 12:37
-
-
Save squaremo/9228773 to your computer and use it in GitHub Desktop.
Topic publisher / consumer
This file contains hidden or 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:25671/%2F') | |
| conn = pika.BlockingConnection(params) | |
| ch = conn.channel() | |
| ch.exchange_declare('topical', exchange_type = 'topic') | |
| ok = ch.queue_declare() | |
| q = ok.method.queue | |
| ch.queue_bind(q, 'topical', sys.argv[1]) | |
| try: | |
| for (f, h, b) in ch.consume(queue=q): | |
| print "%s: %s" % (f.routing_key, b) | |
| ch.basic_ack(f.delivery_tag) | |
| except KeyboardInterrupt: | |
| conn.close() |
This file contains hidden or 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:25671/%2F') | |
| conn = pika.BlockingConnection(params) | |
| ch = conn.channel() | |
| ch.exchange_declare('topical', exchange_type = 'topic') | |
| ch.basic_publish('topical', sys.argv[1], sys.argv[2]) | |
| conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment