forked from paolo-losi/stormed-amqp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ab4923
commit 0e76637
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#! /usr/bin/env python | ||
|
||
import sys | ||
from tornado.ioloop import IOLoop | ||
from stormed import Connection, Message | ||
|
||
# delivery_mode=2 makes message persistent | ||
routing_key = sys.argv[1] if len(sys.argv) > 1 else 'anonymous.info' | ||
msg = Message(' '.join(sys.argv[2:]) or 'Hello World!') | ||
|
||
def on_connect(): | ||
ch = conn.channel() | ||
ch.exchange_declare(exchange='topic_logs', type='topic') | ||
ch.publish(msg, exchange='topic_logs', routing_key=routing_key) | ||
conn.close(callback=done) | ||
|
||
def done(): | ||
print " [x] Sent %r:%r" % (routing_key, msg.body) | ||
io_loop.stop() | ||
|
||
conn = Connection(host='localhost') | ||
conn.connect(on_connect) | ||
io_loop = IOLoop.instance() | ||
io_loop.start() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#! /usr/bin/env python | ||
import sys | ||
from tornado.ioloop import IOLoop | ||
from stormed import Connection, Message | ||
|
||
binding_keys = sys.argv[1:] | ||
if not binding_keys: | ||
print >> sys.stderr, "Usage: %s [binding_key] ..." % sys.argv[0] | ||
sys.exit(1) | ||
|
||
ch = None | ||
|
||
def on_connect(): | ||
global ch | ||
ch = conn.channel() | ||
ch.exchange_declare(exchange='topic_logs', type='topic') | ||
ch.queue_declare(exclusive=True, callback=with_temp_queue) | ||
|
||
def with_temp_queue(queue_name, message_count, consumer_count): | ||
for binding_key in binding_keys: | ||
ch.queue_bind(exchange='topic_logs', | ||
queue=queue_name, | ||
routing_key=binding_key) | ||
ch.consume(queue_name, callback, no_ack=True) | ||
|
||
def callback(msg): | ||
print " [x] %r:%r" % (msg.rx_data.routing_key, msg.body) | ||
|
||
conn = Connection(host='localhost') | ||
conn.connect(on_connect) | ||
io_loop = IOLoop.instance() | ||
print ' [*] Waiting for logs. To exit press CTRL+C' | ||
try: | ||
io_loop.start() | ||
except KeyboardInterrupt: | ||
conn.close(io_loop.stop) |