介绍
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",