天天看點

RocketMQ4.0.0環境搭建及HelloWorld一、linux平台下搭建二、windows平台下搭建

一、linux平台下搭建

1 準備條件:64bit JDK 1.7+;且配置好JAVA_HOME環境變量

2 去apache官網Downloading the Apache RocketMQ Releases下載下傳rocketmq-all-4.0.0-incubating-bin-release.zip,注意:最好要Binary版,不然後續啟動會報ClassNotFound錯誤。如果官網已經沒有4.0.0版本或者無法連接配接到官網,也可以到我的資源RocketMQ4.0.0安裝包下載下傳。

3 解壓檔案:unzip rocketmq-all-4.0.0-incubating-bin-release.zip

4 進入解壓後的目錄apache-rocketmq-all

5 啟動 Name Server:

nohup sh bin/mqnamesrv &
           

6 啟動Broker:

!!!(記得加 autoCreateTopicEnable=true ,否則會報No route info of this topic錯誤)

測試:

啟動 Producer:

export NAMESRV_ADDR=localhost:

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
           

啟動 Consumer:

二、windows平台下搭建

很悲傷,RocketMQ4.0.0版本暫無windows版,但是我們還是可以在windows平台下使用和練習。

1 在rocketmq的github位址 将源代碼導入到本地。

如果該位址版本已更新,可以到我的github位址下載下傳,以確定是4.0.0版本。

2 添加環境變量ROCKETMQ_HOME ,設定值為:127.0.0.1:9876

3 啟動Name Server:

(a) 進入org.apache.rocketmq.namesrv包内的NamesrvStartup類,修改109行的

将namesrvConfig.getRocketmqHome()改為你工程存放的目錄,例如我的設定是

(b) run NamesrvStartup類的main方法

4 啟動Broker:

(a) 進入org.apache.rocketmq.broker包内的BrokerStartup類,修改183行的

将brokerConfig.getRocketmqHome()改為你工程存放的目錄,例如我的設定是

(b) run BrokerStartup的main方法

5 測試

進入example子產品下的org.apache.rocketmq.example.quickstart包,先run Producer的main方法,再run Consumer的main方法。看到如下輸出,表示配置成功。

SendResult [sendStatus=SEND_OK, msgId=0A762C5D210447415DBF06CF99C203E0, offsetMsgId=0A762C5D00002A9F0000000000060E64, messageQueue=MessageQueue [topic=TopicTest, brokerName=SF0001139954B, queueId=1], queueOffset=498]
SendResult [sendStatus=SEND_OK, msgId=0A762C5D210447415DBF06CF99C503E1, offsetMsgId=0A762C5D00002A9F0000000000060F18, messageQueue=MessageQueue [topic=TopicTest, brokerName=SF0001139954B, queueId=2], queueOffset=498]
SendResult [sendStatus=SEND_OK, msgId=0A762C5D210447415DBF06CF99C703E2, offsetMsgId=0A762C5D00002A9F0000000000060FCC, messageQueue=MessageQueue [topic=TopicTest, brokerName=SF0001139954B, queueId=3], queueOffset=498]
           
ConsumeMessageThread_9 Receive New Messages: [MessageExt [queueId=, storeSize=, queueOffset=, sysFlag=, bornTimestamp=, bornHost=/:, storeTimestamp=, storeHost=/:, msgId=A762C5D00002A9F000000000005E86C, commitLogOffset=, bodyCRC=, reconsumeTimes=, preparedTransactionOffset=, toString()=Message [topic=TopicTest, flag=, properties={TAGS=TagA, WAIT=true, UNIQ_KEY=0A762C5D210447415DBF06CF994B03AA, MAX_OFFSET=500, CONSUME_START_TIME=1488455116459, MIN_OFFSET=0}, body=]]]
ConsumeMessageThread_18 Receive New Messages: [MessageExt [queueId=, storeSize=, queueOffset=, sysFlag=, bornTimestamp=, bornHost=/:, storeTimestamp=, storeHost=/:, msgId=A762C5D00002A9F000000000005E59C, commitLogOffset=, bodyCRC=, reconsumeTimes=, preparedTransactionOffset=, toString()=Message [topic=TopicTest, flag=, properties={TAGS=TagA, WAIT=true, UNIQ_KEY=0A762C5D210447415DBF06CF994303A6, MAX_OFFSET=500, CONSUME_START_TIME=1488455116459, MIN_OFFSET=0}, body=]]]
           

繼續閱讀