import pika

# 设置RabbitMQ服务器的连接参数，使用自定义端口9876
connection_params = pika.ConnectionParameters('rocketmq.qa.huohua.cn', 9876)
connection = pika.BlockingConnection(connection_params)
channel = connection.channel()

# 声明一个队列，如果队列不存在则会创建
queue_name = 'my_queue'
channel.queue_declare(queue=queue_name)

# 发布消息到指定的队列
message = 'Hello, World!'
channel.basic_publish(exchange='',
                      routing_key=queue_name,
                      body=message)
print(f" [x] Sent '{message}'")
# 关闭连接
connection.close()
