技术架构

RocketMQ拥有4个角色
生产者:用来生产消息,属于推送的一方
消费者:用来消费消息,属于订阅,查询的一方
Broker:消息的存储和投递
NameServer:路由注册中心,用于收集生产者,消费者,Broker的IP
启动RocketMQ
启动个rocketmq事情真的多....
在每个部分的启动项配置ROCKETMQ_HOME={你rocketmq项目存放的位置}
先git clone项目,在rocktmq文件夹下添加3个文件夹conf,logs,stores
NameServer
把distribution文件夹下的3个文件复制到我们新建的conf文件夹下,并作如下修改
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
#nameServer地址,分号分割
namesrvAddr = 127.0.0.1:9876
brokerIP1 = 192.168.1.102
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
#存储路径,注意是文件夹
storePathRootDir = /Users/bytedance/java/rocketmq/stores
#commitLog存储路径,注意是文件夹
storePathCommitLog = /Users/bytedance/java/rocketmq/stores/commitlog
#消费队列存储路径,注意是文件夹
storePathConsumeQueue = /Users/bytedance/java/rocketmq/stores/consumequeue
#消息索引存储路径,注意是文件夹
storePathIndex = /Users/bytedance/java/rocketmq/stores/index
#checkpoint文件存储路径,注意是文件
storeCheckpoint = /Users/bytedance/java/rocketmq/stores/checkpoint
#abort文件存储路径,注意是文件
abortFile = /Users/bytedance/java/rocketmq/stores/abort
其他两个文件,把user.home改成ROCKETMQ_HOME就可以了,接下来就是启动NameSrv了
启动成功!!!!

Broker
除了ROCKETMQ_HOME的配置之外,还需要参数配置,指定broker配置文件在哪

启动成功!!!!

遇到的坑
- checkpoint和abort都是文件....不要建成文件夹!
- brokerIP1指定成本地的IP,可以ifcongfig查看,默认使用docker容器的IP,生产者连接不到
Producer&Consumer
生产者加上producer.setNamesrvAddr("127.0.0.1:9876");
消费者加上consumer.setNamesrvAddr("127.0.0.1:9876");
先启动生产者,再启动消费者即可看到消息被消费了