Browse Source

업데이트 'src/main/python/kr/co/swh/lecture/opensource/rabbitmq/receiveTopic.py'

tobby48 1 year ago
parent
commit
319d20972b

+ 6
- 5
src/main/python/kr/co/swh/lecture/opensource/rabbitmq/receiveTopic.py View File

@@ -4,19 +4,20 @@ import sys
4 4
 connection = pika.BlockingConnection(pika.ConnectionParameters(host='183.99.87.90'))
5 5
 channel = connection.channel()
6 6
 
7
-channel.exchange_declare(exchange='topic_logs', exchange_type='topic')
7
+exchange_name = 'topic_logs'
8
+channel.exchange_declare(exchange=exchange_name, exchange_type='topic')
8 9
 
9
-result = channel.queue_declare(queue='', exclusive=True)
10
+result = channel.queue_declare(queue='')
10 11
 queue_name = result.method.queue
11 12
 
12
-channel.queue_bind(exchange='topic_logs',
13
+channel.queue_bind(exchange=exchange_name,
13 14
                        queue=queue_name,
14 15
                        routing_key="key")
15 16
 
16 17
 def callback(ch, method, properties, body):
17
-    print(" [x] %r:%r" % (method.routing_key, body))
18
+    print(" [x] %s:%s" % (method.routing_key, body))
18 19
 
19 20
 channel.basic_consume(
20
-        queue=queue_name, on_message_callback=callback, auto_ack=True)
21
+        queue=queue_name, on_message_callback=callback)
21 22
 
22 23
 channel.start_consuming()