########################### 消费者1 ##########################
import pika
import sys
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='192.168.136.8'))
channel = connection.channel()
channel.exchange_declare(exchange='direct_logs',
type='direct')
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='direct_logs',
queue=queue_name,
routing_key='yes')
channel.queue_bind(exchange='direct_logs',
queue=queue_name,
routing_key='db')
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] %r:%r" % (method.routing_key, body))
channel.basic_consume(callback,
queue=queue_name,
no_ack=True)
channel.start_consuming()