从 https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.2.0/rocketmq-all-4.2.0-source-release.zip 下载 4.2.0 的源码版本,执行以下命令来解压4.2.0源码版本并构建二进制文件。
unzip rocketmq-all-4.2.0-source-release.zip cd rocketmq-all-4.2.0/ mvn -Prelease-all -DskipTests clean install -U
构建成功后 进入到目录 :
cd distribution/target/apache-rocketmq
nohup sh bin/mqnamesrv & ##查看日志 tail -f ~/logs/rocketmqlogs/namesrv.log
PS:启动过程可能会因为内存不够而出错,将启动参数的内存配置修改一下 vim bin/runserver.sh
nvalid initial heap size: -Xms4g
The specified size exceeds the maximum representable size.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit
nohup sh bin/mqbroker -n localhost:9876 & tail -f ~/logs/rocketmqlogs/broker.log
PS:启动过程可能会因为内存不够而出错,将启动参数的内存配置修改一下 bin/runbroker.sh
Invalid initial heap size: -Xms8g
The specified size exceeds the maximum representable size.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
在发送/接收消息之前,我们需要告诉客户名称服务器的位置。RocketMQ 提供了多种方法来实现这一点。为了简单起见,我们使用环境变量NAMESRV_ADDR
export NAMESRV_ADDR=localhost:9876 sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
sh bin/mqshutdown broker //停止 broker sh bin/mqshutdown namesrv //停止 nameserver
上面几个启动和关闭 name server 和 broker 的就不再说了,