Skip to content

Instantly share code, notes, and snippets.

@squaremo
Created February 26, 2014 12:37
Show Gist options
  • Select an option

  • Save squaremo/9228773 to your computer and use it in GitHub Desktop.

Select an option

Save squaremo/9228773 to your computer and use it in GitHub Desktop.
Topic publisher / consumer
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()
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