zoukankan      html  css  js  c++  java
  • python---RabbitMQ(4)exchange中模糊匹配topic

    和关键字相似

    生产者:

    # 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()
  • 相关阅读:
    mysql日期加减
    cron 配置计划任务的书写格式(quartz 时间配置)
    空值排序问题
    update 表名 set 字段=值,数据更新
    insert into 数据插入
    SQL里面的char类型
    SQL使用代码创建数据完整性,约束
    SQL制表
    sql创建数据库
    验证码
  • 原文地址:https://www.cnblogs.com/ssyfj/p/8576008.html
Copyright © 2011-2022 走看看