RocketMQ单机环境

RocketMQ单机环境搭建文档

单机环境搭建

依赖环境

  1. 64 位操作系统,Linux/ Unix/Mac OS

  2. 64位JDK 1.8+

  3. Maven 3.2.x

  4. Git

代码下载

从github上clone代码 rocketmq

> git clone https://github.com/apache/rocketmq.git

项目构建

> cd rocketmq
# meavn打包
> mvn -Prelease-all -DskipTests clean install -U
# 这里的4.5.x是版本号,可能不同,请注意自己的版本
> cd distribution/target/rocketmq-4.5.x/rocketmq-4.5.x

启动 NameServer

# 启动NameServer
> nohup sh bin/mqnamesrv &
# 查看日志,确认是否成功
> tail -f ~/logs/rocketmqlogs/namesrv.log

2019-9-27 21:04:10 INFO NSScheduledThread1 - ----
...
#出现下面信息成功
  The Name Server boot success...

启动 Broker

# 启动Broker
> nohup sh bin/mqbroker -n localhost:9876 &
# 查看日志,确认是否成功
> tail -f ~/logs/rocketmqlogs/broker.log 
  The broker[%s, 172.30.30.233:10911] boot success...

无法正常启动时,尝试下面命令可看到详细错误信息

sh bin/mqnamesrv

sh bin/mqbroker -n localhost:9876

发送和接收消息

生产者发送消息

 > export NAMESRV_ADDR=localhost:9876
 > sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
 # 出现下面信息成功发送
  SendResult [sendStatus=SEND_OK, msgId= ...

消费者消费消息

> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
# 出现下面信息成功消费
 ConsumeMessageThread_%d Receive New Messages: [MessageExt...

关闭服务

# 关闭 broker
> sh bin/mqshutdown broker
The mqbroker(36695) is running...
Send shutdown request to mqbroker(36695) OK

# 关闭 namesrv
> sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running...
Send shutdown request to mqnamesrv(36664) OK

参考文档:

Last updated