File tree Expand file tree Collapse file tree 6 files changed +77
-34
lines changed
Expand file tree Collapse file tree 6 files changed +77
-34
lines changed 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 = 'logs' , type = 'fanout' )
11+ client .wait (promise )
12+
13+ message = ' ' .join (sys .argv [1 :]) or "info: Hello World!"
14+ promise = client .basic_publish (exchange = 'logs' , routing_key = '' , body = message )
15+ client .wait (promise )
16+
17+ print " [x] Sent %r" % (message ,)
18+ client .close ()
Original file line number Diff line number Diff line change 33import sys
44
55client = puka .Client ("amqp://localhost/" )
6- ticket = client .connect ()
7- client .wait (ticket )
6+ promise = client .connect ()
7+ client .wait (promise )
88
9- ticket = client .queue_declare (queue = 'task_queue' )
10- client .wait (ticket )
9+
10+ promise = client .queue_declare (queue = 'task_queue' , durable = True )
11+ client .wait (promise )
1112
1213message = ' ' .join (sys .argv [1 :]) or "Hello World!"
13- ticket = client .basic_publish (exchange = '' ,
14- routing_key = 'task_queue' ,
15- body = message )
16- client .wait (ticket )
14+ promise = client .basic_publish (exchange = '' ,
15+ routing_key = 'task_queue' ,
16+ body = message ,
17+ headers = {'delivery_mode' : 2 })
18+ client .wait (promise )
1719print " [x] Sent %r" % (message ,)
1820
21+ client .close ()
Original file line number Diff line number Diff line change 22import puka
33
44client = puka .Client ("amqp://localhost/" )
5- ticket = client .connect ()
6- client .wait (ticket )
5+ promise = client .connect ()
6+ client .wait (promise )
77
88
9- ticket = client .queue_declare (queue = 'hello' )
10- client .wait (ticket )
9+ promise = client .queue_declare (queue = 'hello' )
10+ client .wait (promise )
11+
1112
1213print ' [*] Waiting for messages. To exit press CTRL+C'
1314
14- consume_ticket = client .basic_consume (queue = 'hello' ,
15- no_ack = True )
15+ consume_promise = client .basic_consume (queue = 'hello' , no_ack = True )
1616while True :
17- msg_result = client .wait (consume_ticket )
18- print " [x] Received %r %r " % (msg_result ['body' ], msg_result ,)
17+ msg_result = client .wait (consume_promise )
18+ print " [x] Received %r" % (msg_result ['body' ],)
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import puka
3+
4+ client = puka .Client ("amqp://localhost/" )
5+ promise = client .connect ()
6+ client .wait (promise )
7+
8+
9+ promise = client .exchange_declare (exchange = 'logs' , type = 'fanout' )
10+ client .wait (promise )
11+
12+ promise = client .queue_declare (exclusive = True )
13+ queue_name = client .wait (promise )['queue' ]
14+
15+ promise = client .queue_bind (exchange = 'logs' , queue = queue_name )
16+ client .wait (promise )
17+
18+
19+ print ' [*] Waiting for logs. To exit press CTRL+C'
20+
21+ consume_promise = client .basic_consume (queue = queue_name , no_ack = True )
22+ while True :
23+ msg_result = client .wait (consume_promise )
24+ print " [x] %r" % (msg_result ['body' ],)
Original file line number Diff line number Diff line change 22import puka
33
44client = puka .Client ("amqp://localhost/" )
5- ticket = client .connect ()
6- client .wait (ticket )
5+ promise = client .connect ()
6+ client .wait (promise )
77
8- ticket = client .queue_declare (queue = 'hello' )
9- client .wait (ticket )
108
11- ticket = client .basic_publish (exchange = '' ,
12- routing_key = 'hello' ,
13- body = "Hello world!" )
14- client .wait (ticket )
9+ promise = client .queue_declare (queue = 'hello' )
10+ client .wait (promise )
1511
12+ promise = client .basic_publish (exchange = '' ,
13+ routing_key = 'hello' ,
14+ body = "Hello World!" )
15+ client .wait (promise )
1616
1717print " [x] Sent 'Hello World!'"
18+ client .close ()
Original file line number Diff line number Diff line change 33import time
44
55client = puka .Client ("amqp://localhost/" )
6- ticket = client .connect ()
7- client .wait (ticket )
6+ promise = client .connect ()
7+ client .wait (promise )
88
99
10- ticket = client .queue_declare (queue = 'task_queue' )
11- client .wait (ticket )
10+ promise = client .queue_declare (queue = 'task_queue' , durable = True )
11+ client .wait (promise )
1212print ' [*] Waiting for messages. To exit press CTRL+C'
1313
14- consume_ticket = client .basic_consume (queue = 'task_queue' ,
15- prefetch_count = 1 )
14+ consume_promise = client .basic_consume (queue = 'task_queue' , prefetch_count = 1 )
1615while True :
17- msg_result = client .wait (consume_ticket )
18- body = msg_result ['body' ]
19- print " [x] Received %r" % (body ,)
16+ msg_result = client .wait (consume_promise )
17+ print " [x] Received %r" % (msg_result ['body' ],)
2018 time .sleep ( body .count ('.' ) )
2119 print " [x] Done"
2220 client .basic_ack (msg_result )
23-
You can’t perform that action at this time.
0 commit comments