Permalink
Browse files

examples for tutorial 3 + API fix

  • Loading branch information...
1 parent e921a14 commit f3b5e1b074870d3e8cc6e117d81d67c7e0acba2f @paolo-losi committed Jan 10, 2011
Showing with 52 additions and 2 deletions.
  1. +23 −0 examples/tutorial3/emit_log.py
  2. +27 −0 examples/tutorial3/receive_logs.py
  3. +2 −2 stormed/channel.py
View
23 examples/tutorial3/emit_log.py
@@ -0,0 +1,23 @@
+#! /usr/bin/env python
+
+import sys
+from tornado.ioloop import IOLoop
+from stormed import Connection, Message
+
+# delivery_mode=2 makes message persistent
+msg = Message(' '.join(sys.argv[1:]) or 'info: Hello World!')
+
+def on_connect():
+ ch = conn.channel()
+ ch.exchange_declare(exchange='logs', type='fanout')
+ ch.publish(msg, exchange='logs', routing_key='')
+ conn.close(callback=done)
+
+def done():
+ print " [x] Sent %r" % msg.body
+ io_loop.stop()
+
+conn = Connection(host='localhost')
+conn.connect(on_connect)
+io_loop = IOLoop.instance()
+io_loop.start()
View
27 examples/tutorial3/receive_logs.py
@@ -0,0 +1,27 @@
+#! /usr/bin/env python
+from tornado.ioloop import IOLoop
+from stormed import Connection, Message
+
+ch = None
+
+def on_connect():
+ global ch
+ ch = conn.channel()
+ ch.exchange_declare(exchange='logs', type='fanout')
+ ch.queue_declare(exclusive=True, callback=with_temp_queue)
+
+def with_temp_queue(queue_name, message_count, consumer_count):
+ ch.queue_bind(exchange='logs', queue=queue_name)
+ ch.consume(queue_name, callback, no_ack=True)
+
+def callback(msg):
+ print " [x] %r" % 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)
View
4 stormed/channel.py
@@ -39,8 +39,8 @@ def exchange_delete(self, exchange, if_unused=False, callback=None):
if_unused = if_unused,
nowait = False), callback)
- def queue_declare(self, queue, passive=False, durable=True, exclusive=False,
- auto_delete=False, callback=None):
+ def queue_declare(self, queue='', passive=False, durable=True,
+ exclusive=False, auto_delete=False, callback=None):
self.send_method(_queue.Declare(ticket = 0,
queue = queue,
passive = passive,

0 comments on commit f3b5e1b

Please sign in to comment.