美文网首页
RocketMQ安装

RocketMQ安装

作者: MiniSoulBigBang | 来源:发表于2021-03-07 22:34 被阅读0次

    1 RocketMQ安装

    1.1 RocketMQ下载

    1.2 安装

    1.2.1 解压rocketmq

    unzip rocketmq-all-4.5.1-bin-release.zip 
    

    1.2.2 启动nameserver

    前台启动

    ./mqnamesrv
    

    后台启动

    nohup ./mqnamesrv > /dev/null 2>&1 & 
    

    1.2.3 启动broker

    前台启动

    ./mqbroker -n 192.168.81.130:9876 autoCreateTopicEnable=true 
    

    后台启动

    nohup ./mqbroker -n 192.168.81.130:9876 autoCreateTopicEnable=true > /dev/null 2>&1 &
    

    1.2.4 安装过程中可能出现的错误

    01.png

    错误原因:JDK版本不匹配,JDK必须是1.8以上。

    02.png

    错误原因:是因为内存不够,导致启动失败。RocketMQ的配置默认是生产环境的配置,设置的jvm的内存大小值比较大,对于学习而言没有必要设置这么大,测试环境的内存往往都不是很大,所以需要调整默认值。
    解决方案:

    修改runserver.sh

    JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn125m -XX:MetaspaceSize=128m - XX:MaxMetaspaceSize=320m"
    

    修改runbroker.sh文件:

    JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
    

    1.2.5 消息测试

    1.2.5.1 配置nameserver地址,设置nameserver服务器

    vi /etc/profile
    export NAMESRV_ADDR=192.168.81.130:9876
    source /etc/profile 
    

    1.2.5.1 测试消息发送命令

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

    测试结果:

    SendResult [sendStatus=SEND_OK, msgId=AC110001473C7D4991AD336AEA5703E0, offsetMsgId=AC11000100002A9F00000000000E8580, messageQueue=MessageQueue [topic=TopicTest, brokerName=itcast, queueId=3], queueOffset=1323] 
    SendResult [sendStatus=SEND_OK, msgId=AC110001473C7D4991AD336AEA5903E1, offsetMsgId=AC11000100002A9F00000000000E8634, messageQueue=MessageQueue [topic=TopicTest, brokerName=itcast, queueId=0], queueOffset=1323] 
    SendResult [sendStatus=SEND_OK, msgId=AC110001473C7D4991AD336AEA5F03E2, offsetMsgId=AC11000100002A9F00000000000E86E8, messageQueue=MessageQueue [topic=TopicTest, brokerName=itcast, queueId=1], queueOffset=1323] 
    SendResult [sendStatus=SEND_OK, msgId=AC110001473C7D4991AD336AEA6103E3, offsetMsgId=AC11000100002A9F00000000000E879C, messageQueue=MessageQueue [topic=TopicTest, brokerName=itcast, queueId=2], queueOffset=1323]
    

    从结果中可以看出发送消息正常

    1.2.5.1 测试消息接收命令

    sh tools.sh org.apache.rocketmq.example.quickstart.Consumer 
    

    测试结果:

    ConsumeMessageThread_3 Receive New Messages: [MessageExt [brokerName=localhost.localdomain, queueId=2, storeSize=203, queueOffset=196, sysFlag=0, bornTimestamp=1608801894315, bornHost=/192.168.81.130:46714, storeTimestamp=1608801894316, storeHost=/192.168.81.130:10911, msgId=C0A8518200002A9F0000000000026ED8, commitLogOffset=159448, bodyCRC=624148161, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1608801970002, UNIQ_KEY=7F000001E8DA29453F447A2EE7AB0312, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 55, 56, 54], transactionId='null'}]] 
    ConsumeMessageThread_9 Receive New Messages: [MessageExt [brokerName=localhost.localdomain, queueId=2, storeSize=203, queueOffset=194, sysFlag=0, bornTimestamp=1608801894298, bornHost=/192.168.81.130:46714, storeTimestamp=1608801894299, storeHost=/192.168.81.130:10911, msgId=C0A8518200002A9F0000000000026880, commitLogOffset=157824, bodyCRC=1158909705, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1608801970002, UNIQ_KEY=7F000001E8DA29453F447A2EE79A030A, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 55, 55, 56], transactionId='null'}]] 
    ConsumeMessageThread_7 Receive New Messages: [MessageExt [brokerName=localhost.localdomain, queueId=1, storeSize=203, queueOffset=129, sysFlag=0, bornTimestamp=1608801893711, bornHost=/192.168.81.130:46714, storeTimestamp=1608801893711, storeHost=/192.168.81.130:10911, msgId=C0A8518200002A9F0000000000019989, commitLogOffset=104841, bodyCRC=7528816, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1608801969928, UNIQ_KEY=7F000001E8DA29453F447A2EE54F0205, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 53, 49, 55], transactionId='null'}]]
    

    从结果中可以看出接收消息正常

    1.2.6 关闭服务

    关闭broker

    ./mqshutdown broker
    

    关闭nameserver

    ./mqshutdown namesrv
    

    相关文章

      网友评论

          本文标题:RocketMQ安装

          本文链接:https://www.haomeiwen.com/subject/bwluqltx.html