tobby48 2 年 前
コミット
440a87f45a
共有1 個のファイルを変更した5 個の追加17 個の削除を含む
  1. 5
    17
      src/main/python/kr/co/swh/lecture/opensource/rabbitmq/sendTopic.py

+ 5
- 17
src/main/python/kr/co/swh/lecture/opensource/rabbitmq/sendTopic.py ファイルの表示

@@ -1,22 +1,10 @@
1 1
 import pika
2
-import sys
3 2
 
4
-connection = pika.BlockingConnection(pika.ConnectionParameters(host='183.99.87.90'))
3
+connection = pika.BlockingConnection(
4
+    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
+channel.basic_publish(exchange='topic_logs', routing_key='key', body='Hello World!')
8 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()
9
+print(" [x] Sent 'Hello World!'")
10
+connection.close()