简介
- RocketMQ-Console是RocketMQ项目的扩展插件,是一个图形化管理控制台,提供Broker集群状态查看,Topic管理,Producer、Consumer状态展示,消息查询等常用功能,这个功能在安装好RocketMQ后需要额外单独安装、运行。
- 命令行管理工具(CLI Admin Tool)对RocketMQ集群的管理提供了更多精细化的管理命令,命令行的方式对操作人员的要求稍高一些,当然,掌握了使用方法,就会简单高效很多。命令行管理工具无需额外安装,已经包含在${RocketMQ_HOME}/bin文件夹下面。
RocketMQ-Console
- 进入rocketmq-externals项目GitHub地址,如下图,可看到RocketMQ项目的诸多扩展项目,其中就包含我们需要下载的rocketmq-console。
- 使用git命令下载项目源码,由于我们仅需要rocketmq-console,故下载此项目对应分支即可。
$ git clone -b release-rocketmq-console-1.0.0 https://github.com/apache/rocketmq-externals.git
- 进入项目文件夹并修改配置文件(中文注释是我添加,为方便解释,请删除,不然打包报错)。
$ cd rocketmq-externals/rocketmq-console/
$ vi src/main/resources/application.properties
#管理后台访问上下文路径,默认为空,如果填写,一定要前面加“/”,后面不要加,否则启动报错
server.contextPath=/rocketmq
#访问端口
server.port=8080
#spring.application.index=true
spring.application.name=rocketmq-console
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
#logback配置文件路径
logging.config=classpath:logback.xml
#if this value is empty,use env value rocketmq.config.namesrvAddr NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876
#Name Server地址,修改成你自己的服务地址
rocketmq.config.namesrvAddr=10.0.74.198:9876;10.0.74.199:9876
#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
rocketmq.config.isVIPChannel=
#rocketmq-console's data path:dashboard/monitor
rocketmq.config.dataPath=/tmp/rocketmq-console/data
#set it false if you don't want use dashboard.default true
rocketmq.config.enableDashBoardCollect=true
Name Server地址默认为空,注释说可以在启动项目后在后台配置,经测试,后台配置切换失败,有报错,所以打包前需修改配置文件明确给出Name Server地址,或者启动服务的时候给出rocketmq.config.namesrvAddr参数值。
- 将项目打成jar包,并运行jar文件。
$ mvn clean package -Dmaven.test.skip=true
$ java -jar target/rocketmq-console-ng-1.0.0.jar
#如果配置文件没有填写Name Server
$ java -jar target/rocketmq-console-ng-1.0.0.jar --rocketmq.config.namesrvAddr='10.0.74.198:9876;10.0.74.199:9876'
- 启动成功后,访问地址http://localhost:8080/rocketmq, 即可进入管理后台操作。
命令行管理工具
上面已经讲过命令行管理工具已经包含在RocketMQ项目中,我们进入项目下的bin文件夹,并执行命令bash mqadmin
,
$ bash mqadmin
The most commonly used mqadmin commands are:
updateTopic Update or create topic
deleteTopic Delete topic from broker and NameServer.
updateSubGroup Update or create subscription group
deleteSubGroup Delete subscription group from broker.
updateBrokerConfig Update broker's config
updateTopicPerm Update topic perm
topicRoute Examine topic route info
topicStatus Examine topic Status info
topicClusterList get cluster info for topic
brokerStatus Fetch broker runtime status data
queryMsgById Query Message by Id
queryMsgByKey Query Message by Key
queryMsgByUniqueKey Query Message by Unique key
queryMsgByOffset Query Message by offset
queryMsgByUniqueKey Query Message by Unique key
printMsg Print Message Detail
printMsgByQueue Print Message Detail
sendMsgStatus send msg to broker.
brokerConsumeStats Fetch broker consume stats data
producerConnection Query producer's socket connection and client version
consumerConnection Query consumer's socket connection, client version and subscription
consumerProgress Query consumers's progress, speed
consumerStatus Query consumer's internal data structure
cloneGroupOffset clone offset from other group.
clusterList List all of clusters
topicList Fetch all topic list from name server
updateKvConfig Create or update KV config.
deleteKvConfig Delete KV config.
wipeWritePerm Wipe write perm of broker in all name server
resetOffsetByTime Reset consumer offset by timestamp(without client restart).
updateOrderConf Create or update or delete order conf
cleanExpiredCQ Clean expired ConsumeQueue on broker.
cleanUnusedTopic Clean unused topic on broker.
startMonitoring Start Monitoring
statsAll Topic and Consumer tps stats
allocateMQ Allocate MQ
checkMsgSendRT check message send response time
clusterRT List All clusters Message Send RT
getNamesrvConfig Get configs of name server.
updateNamesrvConfig Update configs of name server.
getBrokerConfig Get broker config by cluster or special broker!
queryCq Query cq command.
上面清单中左边为命令名称,右边为命令含义的解释,可以看到,大部分我们常用的功能已包含其中,具体如何使用这些命令,可以通过执行bash mqadmin help <command>
来了解细节,我们以常用命令updateTopic
为例,执行bash mqadmin help updateTopic
,打印如下信息:
可以看到,每一个参数项都有解释,理解起来也不困难,现在我们新建一个topic,指定名称为TopicTest,
$ bash mqadmin updateTopic -n '10.0.74.198:9876;10.0.74.199:9876' -c hq-mq-cluster -t TestTopic
create topic to 10.0.74.199:10911 success.
create topic to 10.0.74.198:10911 success.
TopicConfig [topicName=TestTopic, readQueueNums=8, writeQueueNums=8, perm=RW-, topicFilterType=SINGLE_TAG, topicSysFlag=0, order=false]
创建的topic的默认配置也打印出来了,利用topicList
命令查看topic清单,
$ bash mqadmin topicList -n '10.0.74.198:9876;10.0.74.199:9876'
TestTopic
BenchmarkTest
OFFSET_MOVED_EVENT
SELF_TEST_TOPIC
...
可以看见,刚才新建的TopicTest以及一些系统默认的topic。如果想学习了解这些命令的源码实现可以点击查看这里。
RocketMQ的管理工具就讲到这里,更多技巧及原理还有待深究。。。