zoukankan      html  css  js  c++  java
  • 监听Rabbitmq系统日志(python版)

    介绍

    rabbitmq默认有7个交换机,其中amq.rabbitmq.log为系统日志的交换机,这个日志为topic类型,会有三个等级的(routing_key)的日志发送到这个交换机上。

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    
    import pika
    # ########################### 订阅者 ###########################
    credentials = pika.PlainCredentials("用户名","密码")
    connection = pika.BlockingConnection(pika.ConnectionParameters(
        'ip',
        5672,
        '/',
        credentials=credentials))
    
    channel = connection.channel()
    
    
    # 声明队列
    channel.queue_declare(queue='info_queue',durable=True)
    channel.queue_declare(queue='error_queue',durable=True)
    channel.queue_declare(queue='warning_queue',durable=True)
    
    # 绑定
    channel.queue_bind(exchange='amq.rabbitmq.log',queue="info_queue",routing_key="info")
    channel.queue_bind(exchange='amq.rabbitmq.log',queue="error_queue",routing_key="error")
    channel.queue_bind(exchange='amq.rabbitmq.log',queue="warning_queue",routing_key="warning")
    
    print(' [*] Waiting for logs. To exit press CTRL+C')
    
    def callback(ch, method, properties, body):
        print(" [x] %r" % body)
        print(" [x] Done")
        ch.basic_ack(delivery_tag=method.delivery_tag)
    
    channel.basic_consume("info_queue",callback,auto_ack=False)
    channel.basic_consume("error_queue",callback,auto_ack=False)
    channel.basic_consume("warning_queue",callback,auto_ack=False)
    
    channel.start_consuming()
    
    
    '''
    然后发布者只需要给exchange发送消息,然后exchange绑定的多个队列都有这个消息了。订阅者就收到这个消息了。
    '''
  • 相关阅读:
    HDU 1402 A * B Problem Plus FFT
    HDU 4609 3-idiots FFT
    Hihocoder #1527 : 快速乘法 DP
    Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo DP+矩阵快速幂加速
    Codeforces 8VC Venture Cup 2016
    FFT做题记录
    Hackrank Candies DP
    git submodule update --init --recursive
    慢慢长大
    protobuf
  • 原文地址:https://www.cnblogs.com/-wenli/p/13451561.html
Copyright © 2011-2022 走看看