tobby48 2 years ago
parent
commit
06f202eea9

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

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

+ 22
- 0
src/main/python/kr/co/swh/lecture/opensource/rabbitmq/sendTopic.py View File

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