RocketMQ 介绍
Apache RocketMQ™是一个开源的分布式消息传递和流数据平台。
RocketMQ Github:
RocketMQ 文档:
安装依赖
64bit OS, Linux/Unix/Mac + 64bit OS, Linux/Unix/Mac + Maven 3.2.x + Git
安装相关依赖
# 安装maven[root@linuxprobe ~]# sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo[root@linuxprobe ~]# yum install apache-maven -y# 安装git[root@linuxprobe ~]# yum install git -y
克隆和打包
[root@linuxprobe ~]# cd /opt[root@linuxprobe opt]# git clone -b develop https://github.com/apache/incubator-rocketmq.git[root@linuxprobe ~]# cd incubator-rocketmq[root@linuxprobe incubator-rocketmq]# mvn -Prelease-all -DskipTests clean install -U (打包过程可能会比较久)[root@linuxprobe incubator-rocketmq]# cd distribution/target/apache-rocketmq
启动服务
[root@linuxprobe apache-rocketmq]# nohup sh bin/mqnamesrv &# 查看日志[root@linuxprobe apache-rocketmq]# tail -f ~/logs/rocketmqlogs/namesrv.log
启动Broker
# 查看hosts解析[root@linuxprobe ~]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain linuxprobe.com 10.1.1.87 linuxprobe.com # [root@linuxprobe apache-rocketmq]# nohup sh bin/mqbroker -n linuxprobe.com:9876 &[root@linuxprobe apache-rocketmq]# tail -f ~/logs/rocketmqlogs/broker.log
从图中可以看出Broker服务已经启动成功
发送和接送消息
提前设置环境变量:NAMESRV_ADDR
[root@linuxprobe apache-rocketmq]# export NAMESRV_ADDR=linuxprobe.com:9876# 生产环境使用建议设置全局变量[root@linuxprobe apache-rocketmq]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.ProducerSendResult [sendStatus=SEND_OK, msgId= ...[root@linuxprobe apache-rocketmq]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.ConsumerConsumeMessageThread_%d Receive New Messages: [MessageExt...
笔者这里执行获取消息程序的时候出现啦阻塞(暂未解决)
停止服务
[root@linuxprobe apache-rocketmq]# export NAMESRV_ADDR=linuxprobe.com:9876[root@linuxprobe apache-rocketmq]# sh bin/mqshutdown namesrv