import pika
cr = pika.PlainCredentials('admin', '.')
connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.14.87', 5672, '/', cr))
channel = connection.channel()
channel.exchange_declare(exchange='lbw_3',
exchange_type='direct')
SB = "SB_123"
channel.basic_publish(exchange='lbw_3',
routing_key='__1',
body=SB)
print("已发送")
connection.close()
import pika
cr = pika.PlainCredentials('admin', '.')
connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.14.87', 5672, '/', cr))
channel = connection.channel()
channel.exchange_declare(exchange='lbw_3',
exchange_type='direct')
result = channel.queue_declare("", exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='lbw_3',
queue=queue_name,
routing_key='__1'
)
def callback(ch, method, properties, body):
print(body)
ch.basic_ack(delivery_tag=method.delivery_tag)
channel.basic_consume(queue=queue_name,
auto_ack=False,
on_message_callback=callback)
print(1)
channel.start_consuming()