import pika

# 连接 RabbitMQ
connection = pika.BlockingConnection(
    pika.ConnectionParameters(
        host='192.168.66.221',
        credentials=pika.PlainCredentials('admin', '123456')
    )
)

channel = connection.channel()

# 声明队列，添加 durable=True 与生产者保持一致
channel.queue_declare(queue='test_queue', durable=True)

print("等待接收消息...")

def callback(ch, method, properties, body):
    print("收到消息：", body.decode())

# 开始消费
channel.basic_consume(queue='test_queue',
                      on_message_callback=callback,
                      auto_ack=True)

channel.start_consuming()
