1
1
#!/usr/bin/env python
2
2
import os
3
- import pika
4
3
import sys
5
4
5
+ import pika
6
+
6
7
7
8
def main ():
8
9
connection = pika .BlockingConnection (
9
- pika .ConnectionParameters (host = 'localhost' ))
10
+ pika .ConnectionParameters (host = "localhost" ),
11
+ )
10
12
channel = connection .channel ()
11
13
12
- channel .exchange_declare (exchange = ' topic_logs' , exchange_type = ' topic' )
14
+ channel .exchange_declare (exchange = " topic_logs" , exchange_type = " topic" )
13
15
14
- result = channel .queue_declare (queue = '' , exclusive = True )
16
+ result = channel .queue_declare (queue = "" , exclusive = True )
15
17
queue_name = result .method .queue
16
18
17
19
binding_keys = sys .argv [1 :]
@@ -21,24 +23,30 @@ def main():
21
23
22
24
for binding_key in binding_keys :
23
25
channel .queue_bind (
24
- exchange = 'topic_logs' , queue = queue_name , routing_key = binding_key )
26
+ exchange = "topic_logs" ,
27
+ queue = queue_name ,
28
+ routing_key = binding_key ,
29
+ )
25
30
26
- print (' [*] Waiting for logs. To exit press CTRL+C' )
31
+ print (" [*] Waiting for logs. To exit press CTRL+C" )
27
32
28
33
def callback (ch , method , properties , body ):
29
34
print (f" [x] { method .routing_key } :{ body .decode ()} " )
30
35
31
36
channel .basic_consume (
32
- queue = queue_name , on_message_callback = callback , auto_ack = True )
37
+ queue = queue_name ,
38
+ on_message_callback = callback ,
39
+ auto_ack = True ,
40
+ )
33
41
34
42
channel .start_consuming ()
35
43
36
44
37
- if __name__ == ' __main__' :
45
+ if __name__ == " __main__" :
38
46
try :
39
47
main ()
40
48
except KeyboardInterrupt :
41
- print (' Interrupted' )
49
+ print (" Interrupted" )
42
50
try :
43
51
sys .exit (0 )
44
52
except SystemExit :
0 commit comments