官网
http://rocketmq.apache.org/docs/quick-start/
官方文档指引,首先从源码库直接下载源码文件,然后通过maven进行编译构建,期间需要很长一段时间,然后按照指引启动它的脚本文件。
坑位发掘
首先启动namesrv还是挺顺利的,到了broker,就开始第一个坑了
源码默认配置的虚拟机是8g的,本地跑就会导致allocate memory failed之类的错误。
打开同目录下的runbroker.sh文件,修改它的参数。
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx512m -Xmn125m"
终于启动正常了。
然后我们要观察启动日志,它将日志写到了~/logs 目录下。
image.png
查看broker.log日志,发现如下图所示,则broker注册正常。
image.png
或者使用如下命令,查看。
sh mqadmin clusterList -n localhost:9876
image.png
然后我们写代码,写完生产消费者,发现启动又是一场,什么no route to Topic之类的,因为官网启动的时候没自动创建Topic,一顿折腾。
nohup sh bin/mqbroker -n localhost:9876 autoCreateTopicEnable=true -c conf/broker.conf &
下面这个命令,就是上面看到的clusterList中的clusterName,在其中添加一个topic testtopic。
sh mqadmin updateTopic -c DefaultCluster -n localhost:9876 -t testtopic
输入 sh mqadmin的时候,它会有文档指示的。
image.png image.png
关闭mq,脚本在编译好的rocketmq bin下
# 1.关闭Nameserver
sh mqshutdown namesrv
# 2.关闭Broker
sh mqshutdown broker
查看topic列表
sh mqadmin topicList -n 192.168.1.23:9876
删除topic
sh mqadmin deleteTopic –n localhost:9876 –c DefaultCluster –t toDelete
RocketMQ基本架构图
rocketMQ.pngnameserver负责协调broker信息,topic路由等,相当于注册中心。
每一个topic在broker上存在多个副本,每个broker上存在若干个queue控制并发度。每个queue是顺序消费。
Docker部署rocketmq
windows 安装docker toolbox
linux/macos 直接安装docker
pull 速度慢 换阿里云源
#拉取rocketmq
docker pull rocketmqinc/rocketmq
#拉取rocketmq控制台
docker pull styletang/rocketmq-console-ng
#windows下进入宿主机
docker-machine ssh
#启动nameserver
docker run -d -p 9876:9876 -v /opt/data/namesrv/logs:/root/logs -v /opt/data/namesrv/store:/root/store --name rmqnamesrv -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq sh mqnamesrv
#启动broker
docker run -d -p 10911:10911 -p 10909:10909 -v /opt/data/broker/logs:/root/logs -v /opt/rocketmq/data/broker/store:/root/store -v /opt/broker.conf:/opt/rocketmq/conf/broker.conf --name rmqbroker --link rmqnamesrv:namesrv -e "NAMESRV_ADDR=namesrv:9876" -e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq sh mqbroker -c /opt/rocketmq/conf/broker.conf
#启动管理后台
docker run -e "JAVA_OPTS=-Drocketmq.config.namesrvAddr=192.168.99.100:9876 -Drocketmq.config.isVIPChannel=false" -p 8080:8080 -t styletang/rocketmq-console-ng
broker.conf
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = {宿主机ip}
image.png
源码启动
下载rocketmq的源码
image.png在idea添加启动参数
image.png
创建好目录
image.png
拷贝配置文件
image.png
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
brokerClusterName = DefaultCluster
brokerName = broker-localhost
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = 192.168.4.47
#配置存储位置
storePathRootDir=D:\\mqconf\\store
#commitlog 存储路径
storePathCommitLog=D:\\mqconf\\store\\commitlog
#消费队列存储路径
storePathConsumeQueue=D:\\mqconf\\store\\storestore\\consumequeue
#消息索引存储路径
storePathIndex=D:\\mqconf\\store\\index
#checkpoint文件存储路径
storeCheckPoint=D:\\mqconf\\store\\checkpoint
#abort文件存储路径
abortFile=D:\\mqconf\\store\\abort
image.png
image.png
网友评论