rocketmq 安装和快速开始 - xd21303/Notebook GitHub Wiki
官网https://rocketmq.apache.org/docs/quick-start/ 下载二进制解压
启动namesrv
sh bin/mqnamesrv -n 127.0.0.1:9876
启动broker
sh bin/mqbroker -n 127.0.0.1:9876 autoCreateTopicEnable=true -c conf/broker.conf
测试发送消息
export NAMESRV_ADDR=127.0.0.1:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
测试消费消息
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
更新topic
sh bin/mqadmin topicStatus -n 127.0.0.1:9876 -t TopicTest
查看topic 状态
sh bin/mqadmin topicStatus -n 127.0.0.1:9876 -t TopicTest
查看broker列表
sh bin/mqadmin clusterList -n 127.0.0.1:9876
python api
安装
pip install rocketmq
生成消息
from rocketmq.client import Producer, Message
producer = Producer('PID-XXX')
producer.set_namesrv_addr('127.0.0.1:9876')
producer.start()
msg = Message('TopicTest')
msg.set_keys('XXX_key')
msg.set_tags('XXX_tag')
msg.set_body('XXXX_body')
ret = producer.send_sync(msg)
print(ret.status, ret.msg_id, ret.offset)
producer.shutdown()
消费消息
from rocketmq.client import PullConsumer
consumer = PullConsumer('CID_XXX')
consumer.set_namesrv_addr('127.0.0.1:9876')
consumer.start()
for msg in consumer.pull('TopicTest'):
print(msg.id, msg.body)
consumer.shutdown()