码迷,mamicode.com
首页 > 编程语言 > 详细

python---RabbitMQ(4)exchange中模糊匹配topic

时间:2018-03-15 21:06:26      阅读:379      评论:0      收藏:0      [点我收藏+]

标签:gpo   env   usr   pre   routing   rabbit   auth   pika   tor   

和关键字相似

生产者:

# coding:utf8
# __author:  Administrator
# date:      2018/3/15 0015
# /usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
    host=localhost
))

channel = connection.channel()

channel.exchange_declare(exchange=topic_logs,
                         type=topic)

key = ha.ga.ef
message=Hello World
channel.basic_publish(exchange=topic_logs,
                      routing_key=key,
                      body=message)

print("Sent message")
connection.close()

消费者:

# coding:utf8
# __author:  Administrator
# date:      2018/3/15 0015
# /usr/bin/env python
import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters(
    host=localhost
))

channel = connection.channel()

channel.exchange_declare(exchange=topic_logs,
                         type=topic)

result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue

bind_key = ha

channel.queue_bind(exchange=topic_logs,
                   queue=queue_name,
                   routing_key=bind_key)

print(Wait for logs)

def callback(ch, method, properties, body):
    print(body)

channel.basic_consume(callback,
                      queue=queue_name,
                      no_ack=True)

channel.start_consuming()

 

python---RabbitMQ(4)exchange中模糊匹配topic

标签:gpo   env   usr   pre   routing   rabbit   auth   pika   tor   

原文地址:https://www.cnblogs.com/ssyfj/p/8576008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!