在网上找了很多RoketMq的学习资料,大多写的都不能满足我自己的学习需求,所以不如自给自足,动手从零开始。
-
下载源码 :(推荐官网下载)
官网:http://rocketmq.apache.org/dowloading/releases/
Github:https://github.com/apache/rocketmq/ -
解压到本地IDEA工作空间目录(E:\IDEA_WORKPACE\rocketmq)
如下图所示,启动源码的话只需要关注这四个模块,broker,namesrv,distribution,example
-
namesrv环境变量配置,如下图所示:
1.在namesrv工程根目录下新建conf,logs,store文件夹,如下图所示:
2.将distribute工程下conf目录下的broker.conf和logback_broker.xml文件复制到namesrc目录,并将logback_broker.xml更名为logback_namesrv.xml
3.将broker.conf文件修改配置,如下:
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
###########################################
#配置存储位置
storePathRootDir=E:\\IDEA_WORKPACE\\rocketmq\\namesrv\\store
#commitlog 存储路径
storePathCommitLog=E:\\IDEA_WORKPACE\\rocketmq\\namesrv\\store\\commitlog
#消费队列存储路径
storePathConsumeQueue=E:\\IDEA_WORKPACE\\rocketmq\\namesrv\\store\\consumequeue
#消息索引存储路径
storePathIndex=E:\\IDEA_WORKPACE\\rocketmq\\namesrv\\store\\index
#checkpoint文件存储路径
storeCheckPoint=E:\\IDEA_WORKPACE\\rocketmq\\namesrv\\store\\checkpoint
#abort文件存储路径
abortFile=E:\\IDEA_WORKPACE\\rocketmq\\namesrv\\store\\abort
至此namesrv工程完成环境配置,可以正常启动,提示:如果没有进行上面第一步操作,会出现找不到logback_namesrv.xml的报错。
autoCreateTopicEnable=true,设置启动时自动创建Topic.否则后面启动生产这producer时会报错,找不到Topic
1.同样在broker的根目录下创建conf文件夹,并将distribution工程下的broker.conf和logback_broker.xml文件复制到conf目录下,如下图所示:
2.修改broker.conf文件,如下所示:
# 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-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
namesrvAddr=127.0.0.1:9876
brokerIP1=***.**.***.** //broker地址:为本地IP地址
至此可以正常启动broker
启动producer和consumer,需注意添加一句代码:
好啦!rocketMQ源码启动环境正式搭建完成啦!快动起你的小手来实践一下吧!