File tree Expand file tree Collapse file tree 5 files changed +117
-6
lines changed Expand file tree Collapse file tree 5 files changed +117
-6
lines changed Original file line number Diff line number Diff line change @@ -9,18 +9,18 @@ to [Puka](https://github.com/majek/puka) Python library.
99
1010Now you can install ` puka ` using Pip:
1111
12- $ pip install puka
12+ pip install puka
1313
1414You may need to install ` pip ` first:
1515
1616 * On Ubuntu:
1717
18- $ sudo apt-get install python-pip git-core
18+ sudo apt-get install python-pip git-core
1919
20- * On Debian:
20+ * On Debian:
2121
22- $ sudo apt-get install python-setuptools
23- $ sudo easy_install pip
22+ sudo apt-get install python-setuptools
23+ sudo easy_install pip
2424
2525
2626## Code
@@ -35,10 +35,17 @@ You may need to install `pip` first:
3535 python new_task.py
3636 python worker.py
3737
38- [ Tutorial three: Publish/Subscribe] ( http://www.rabbitmq.com/tutorial-three-python.html )
38+ [ Tutorial three: Publish/Subscribe] ( http://www.rabbitmq.com/tutorial-three-python.html ) :
3939
4040 python receive_logs.py
4141 python emit_log.py
4242
43+ [ Tutorial four: Routing] ( http://www.rabbitmq.com/tutorial-four-python.html ) :
4344
45+ python receive_logs_direct.py
46+ python emit_log_direct.py
4447
48+ [ Tutorial five: Topics] ( http://www.rabbitmq.com/tutorial-five-python.html ) :
49+
50+ python receive_logs_topic.py
51+ python emit_log_topic.py
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import puka
3+ import sys
4+
5+ client = puka .Client ("amqp://localhost/" )
6+ promise = client .connect ()
7+ client .wait (promise )
8+
9+
10+ promise = client .exchange_declare (exchange = 'direct_logs' , type = 'direct' )
11+ client .wait (promise )
12+
13+ severity = sys .argv [1 ] if len (sys .argv ) > 1 else 'info'
14+ message = ' ' .join (sys .argv [2 :]) or 'Hello World!'
15+ promise = client .basic_publish (exchange = 'direct_logs' , routing_key = severity ,
16+ body = message )
17+ client .wait (promise )
18+
19+ print " [x] Sent %r:%r" % (severity , message )
20+ client .close ()
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import puka
3+ import sys
4+
5+ client = puka .Client ("amqp://localhost/" )
6+ promise = client .connect ()
7+ client .wait (promise )
8+
9+
10+ promise = client .exchange_declare (exchange = 'topic_logs' , type = 'topic' )
11+ client .wait (promise )
12+
13+ routing_key = sys .argv [1 ] if len (sys .argv ) > 1 else 'anonymous.info'
14+ message = ' ' .join (sys .argv [2 :]) or 'Hello World!'
15+ promise = client .basic_publish (exchange = 'topic_logs' , routing_key = routing_key ,
16+ body = message )
17+ client .wait (promise )
18+
19+ print " [x] Sent %r:%r" % (routing_key , message )
20+ client .close ()
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import puka
3+ import sys
4+
5+ client = puka .Client ("amqp://localhost/" )
6+ promise = client .connect ()
7+ client .wait (promise )
8+
9+
10+ promise = client .exchange_declare (exchange = 'direct_logs' , type = 'direct' )
11+ client .wait (promise )
12+
13+ promise = client .queue_declare (exclusive = True )
14+ queue_name = client .wait (promise )['queue' ]
15+
16+ severities = sys .argv [1 :]
17+ if not severities :
18+ print >> sys .stderr , "Usage: %s [info] [warning] [error]" % (sys .argv [0 ],)
19+ sys .exit (1 )
20+
21+ for severity in severities :
22+ promise = client .queue_bind (exchange = 'direct_logs' , queue = queue_name ,
23+ routing_key = severity )
24+ client .wait (promise )
25+
26+
27+ print ' [*] Waiting for logs. To exit press CTRL+C'
28+
29+ consume_promise = client .basic_consume (queue = queue_name , no_ack = True )
30+ while True :
31+ msg_result = client .wait (consume_promise )
32+ print " [x] %r:%r" % (msg_result ['routing_key' ], msg_result ['body' ])
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import puka
3+ import sys
4+
5+ client = puka .Client ("amqp://localhost/" )
6+ promise = client .connect ()
7+ client .wait (promise )
8+
9+
10+ promise = client .exchange_declare (exchange = 'topic_logs' , type = 'topic' )
11+ client .wait (promise )
12+
13+ promise = client .queue_declare (exclusive = True )
14+ queue_name = client .wait (promise )['queue' ]
15+
16+ binding_keys = sys .argv [1 :]
17+ if not binding_keys :
18+ print >> sys .stderr , "Usage: %s [binding_key]..." % (sys .argv [0 ],)
19+ sys .exit (1 )
20+
21+ for binding_key in binding_keys :
22+ promise = client .queue_bind (exchange = 'topic_logs' , queue = queue_name ,
23+ routing_key = binding_key )
24+ client .wait (promise )
25+
26+
27+ print ' [*] Waiting for logs. To exit press CTRL+C'
28+
29+ consume_promise = client .basic_consume (queue = queue_name , no_ack = True )
30+ while True :
31+ msg_result = client .wait (consume_promise )
32+ print " [x] %r:%r" % (msg_result ['routing_key' ], msg_result ['body' ])
You can’t perform that action at this time.
0 commit comments