Windows安装RocketMQ,RocketMQ Windows安装和使用
Posted 蕃薯耀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows安装RocketMQ,RocketMQ Windows安装和使用相关的知识,希望对你有一定的参考价值。
Windows安装RocketMQ,RocketMQ Windows安装和使用
================================
©Copyright 蕃薯耀 2021-05-12
https://www.cnblogs.com/fanshuyao/
一、Windows安装RocketMQ
RocketMQ下载地址:
https://github.com/apache/rocketmq/releases
1、解压rocketmq-all-4.8.0-bin-release.zip到
D:\\0soft\\rocketmq-all-4.8.0
2、RocketMQ配置环境变量:
ROCKETMQ_HOME D:\\0soft\\rocketmq-all-4.8.0 NAMESRV_ADDR localhost:9876
PATH属性增加:
%ROCKETMQ_HOME%\\bin
3、RocketMQ修改日志文件目录
(这步可以省略,默认是在用户的目录是,但为了方便,修改日志存放目录):
进入目录:
D:\\0soft\\rocketmq-all-4.8.0\\conf
修改3个xml文件(请先备份):
logback_namesrv.xml
logback_broker.xml
logback_tools.xml
将所有${user.home}/logs,替换成:D:/0soft/rocketmq-all-4.8.0/logs,具体目录自己定义。
最后生成的日志文件在下面的目录:
D:\\0soft\\rocketmq-all-4.8.0\\logs\\rocketmqlogs
4、RocketMQ修改内存参数,默认的内存太大(记得先备份相应的文件)
进入目录:
D:\\0soft\\rocketmq-all-4.8.0\\bin
修改:runserver.cmd(记得先备份文件):
将:
set "JAVA_OPT=%JAVA_OPT% -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
修改成:
set "JAVA_OPT=%JAVA_OPT% -server -Xms128m -Xmx256m -Xmn64m -XX:MetaspaceSize=32m -XX:MaxMetaspaceSize=64m"
修改:runbroker.cmd(记得先备份文件):
将:
set "JAVA_OPT=%JAVA_OPT% -server -Xms2g -Xmx2g -Xmn1g"
set "JAVA_OPT=%JAVA_OPT% -XX:MaxDirectMemorySize=15g"
修改成:
set "JAVA_OPT=%JAVA_OPT% -server -Xms128m -Xmx128m -Xmn64m"
set "JAVA_OPT=%JAVA_OPT% -XX:MaxDirectMemorySize=1g"
5、RocketMQ启动Name Server:
打开一个新的cmd命令窗口,并进入到bin目录:
D:\\0soft\\rocketmq-all-4.8.0\\bin>mqnamesrv
或者(前提是配置Path路径):
mqnamesrv
启动结果:
D:\\0soft\\rocketmq-all-4.8.0\\bin>mqnamesrv
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON
6、RocketMQ启动:Broker
打开一个新的cmd命令窗口,并进入到bin目录:
D:\\0soft\\rocketmq-all-4.8.0\\bin>mqbroker.cmd -n localhost:9876 autoCreateTopicEnable=true
或者(前提是配置Path路径):
mqbroker.cmd -n localhost:9876 autoCreateTopicEnable=true
启动结果:
D:\\0soft\\rocketmq-all-4.8.0\\bin>mqbroker.cmd -n localhost:9876 autoCreateTopicEnable=true
The broker[XXZX-liqiongy-10, 168.168.2.120:10911] boot success. serializeType=JSON and name server is localhost:9876
7、RocketMQ测试发送消息:
打开一个新的命令窗口,输入下面的命令:
tools.cmd org.apache.rocketmq.example.quickstart.Producer
运行结果:
C:\\Users\\liqiongy>tools.cmd org.apache.rocketmq.example.quickstart.Producer
14:52:04.556 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
RocketMQLog:WARN Please initialize the logger system properly.
SendResult [sendStatus=SEND_OK, msgId=7F00000126B80D71636136B05B2003E6, offsetMsgId=A8A8027800002A9F00000000000316F4, messageQueue=MessageQueue [topic=TopicTest, brokerName=XXZX-liqiongy-10, queueId=3], queueOffset=249]
SendResult [sendStatus=SEND_OK, msgId=7F00000126B80D71636136B05B2103E7, offsetMsgId=A8A8027800002A9F00000000000317BF, messageQueue=MessageQueue [topic=TopicTest, brokerName=XXZX-liqiongy-10, queueId=0], queueOffset=249]
14:52:07.337 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[168.168.2.120:10911] result: true
14:52:07.338 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[127.0.0.1:9876] result: true
8、RocketMQ测试接收消息:
打开一个新的命令窗口,输入下面的命令:
tools.cmd org.apache.rocketmq.example.quickstart.Consumer
运行结果:
C:\\Users\\liqiongy>tools.cmd org.apache.rocketmq.example.quickstart.Consumer
14:54:08.623 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
Consumer Started.
ConsumeMessageThread_3 Receive New Messages: [MessageExt [brokerName=XXZX-liqiongy-10, queueId=3, storeSize=201, queueOffset=1, sysFlag=0, bornTimestamp=1620715925363, bornHost=/168.168.2.120:60949, storeTimestamp=1620715925364, storeHost=/168.168.2.120:10911, msgId=A8A8027800002A9F00000000000004B6, commitLogOffset=1206, bodyCRC=1307562618, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic=\'TopicTest\', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1620716049251, UNIQ_KEY=7F00000126B80D71636136B053730006, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 54], transactionId=\'null\'}]]
ConsumeMessageThread_20 Receive New Messages: [MessageExt [brokerName=XXZX-liqiongy-10, queueId=1, storeSize=201, queueOffset=2, sysFlag=0, bornTimestamp=1620715925368, bornHost=/168.168.2.120:60949, storeTimestamp=1620715925369, storeHost=/168.168.2.120:10911, msgId=A8A8027800002A9F0000000000000648, commitLogOffset=1608, bodyCRC=710410109, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic=\'TopicTest\', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1620716049253, UNIQ_KEY=7F00000126B80D71636136B053780008, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 56], transactionId=\'null\'}]]
9、RocketMQ关闭Servers:
开发环境,可以直接关闭cmd命令窗口
但生产环境不要这样做,而是要打开一个新的命令窗口,分别执行下面的命令:
先关闭broker,再关闭name server
mqshutdown.cmd broker
mqshutdown.cmd namesrv
官方文档见:
https://rocketmq.apache.org/docs/quick-start/
二、Linux RocketMQ安装
1、Linux RocketMQ安装配置和使用,Centos7 RocketMQ4安装配置
https://www.cnblogs.com/fanshuyao/p/14200170.html
2、Linux RocketMQ双主双从,Centos7 RocketMQ4集群(双主双从)
https://www.cnblogs.com/fanshuyao/p/14200573.html
三、RocketMQ客户端实现示例
1、普通示例
https://github.com/apache/rocketmq/tree/master/example/src/main/java/org/apache/rocketmq/example
2、SpringBoot示例
https://github.com/apache/rocketmq-spring
(时间宝贵,分享不易,捐赠回馈,^_^)
================================
©Copyright 蕃薯耀 2021-05-12
https://www.cnblogs.com/fanshuyao/
以上是关于Windows安装RocketMQ,RocketMQ Windows安装和使用的主要内容,如果未能解决你的问题,请参考以下文章