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/