rocketmq消息服务入门笔记

rocketmq日志问题:随着消息服务持续运行,日志量会越来越大,实际工作中可能会达到20G。当日志占用C盘的90%时,消息服务可能会出现警告,无法接收存储消息。此时应该想方法调整日志存储位置,或者给C盘扩容。

以前可视化运维管理界面应用程序在项目rocketmq-externals中rocketmq-console目录下:

https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console

后面再次使用时才发现仓库改成rocketmq-dashboard了,已经找不到rocketmq-console。

rocketmq-dashboard可视化运维管理界面源码

https://github.com/apache/rocketmq-dashboard

rocketmq入门实践

必备环境

  1. 64bit OS,Linux/Unix/Mac is recommended;(Windows user see guide below)
  2. 64bit JDK 1.8+;
  3. Maven 3.2.x;如果没有设置指定maven目录,默认下载jar包在C盘.m2目录
  4. Git;
  5. 4g+ free disk for Broker server

一、快速入门

01 配置环境

配置环境变量(settings environment):Windows10环境可以配置到path环境变量中。

1
2
ROCKETMQ_HOME="D:\rocketmq-all-4.9.1-bin-release"
NAMESRV_ADDR="localhost:9876"

注意:ROCKETMQ_HOME配置为你解压后的rocketmq路径,比如演示:D:\rocketmq-all-4.9.1-bin-release\bin。

如果没有配置JDK环境变量,使用记事本或者sublime text编辑mqnamesrv.cmd和mqbroker.cmd文件指定JDK路径即可,使用set设置JAVA_HOME(测试使用)。

1
2
set JAVA_HOME=D:\jdk8
set JAVA_HOME=D:\JavaEE\jdk8\jdk1.8.0_151

Windows平台启动如下两个服务,先启动mqnamesrv服务,再启动mqbroker服务:

  1. mqnamesrv.cmd
  2. mqbroker.cmd
1
2
3
4
5
6
7
8
9
10
11
12
D:\rocketmq-all-4.9.1-bin-release\bin>mqnamesrv.cmd

D:\rocketmq-all-4.9.1-bin-release\bin>set JAVA_HOME=D:\JavaEE\jdk8\jdk1.8.0_151
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON


D:\rocketmq-all-4.9.1-bin-release\bin>mqbroker.cmd

D:\rocketmq-all-4.9.1-bin-release\bin>set JAVA_HOME=D:\JavaEE\jdk8\jdk1.8.0_151
The broker[user, 192.168.245.1:10911] boot success. serializeType=JSON and name server is localhost:9876

启动后日志管理(logs在C盘用户目录下):

  1. consolelogs
  2. rocketmqlogs

启动rocketmq-dashboard-1.0.1-SNAPSHOT.jar服务

D:\rocketmq-dashboard>java -jar target\rocketmq-dashboard-1.0.1-SNAPSHOT.jar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
D:\rocketmq-dashboard>java -jar target\rocketmq-dashboard-1.0.1-SNAPSHOT.jar

...
21:14:48,915 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/D:/rocketmq-dashboard/target/rocketmq-dashboard-1.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/logback.xml]
21:14:48,935 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@1bce4f0a - URL [jar:file:/D:/rocketmq-dashboard/target/rocketmq-dashboard-1.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/logback.xml] is not of type file
...
21:14:49,206 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1580893732 - Will use the pattern C:/Users/user/logs/consolelogs/rocketmq-console-%d{yyyy-MM-dd}.%i.log for the active file
21:14:49,210 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@5c3bd550 - The date pattern is 'yyyy-MM-dd' from file name pattern 'C:/Users/user/logs/consolelogs/rocketmq-console-%d{yyyy-MM-dd}.%i.log'.
...
21:14:49,229 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: C:\Users\user/logs/consolelogs/rocketmq-console.log
21:14:49,229 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [C:\Users\user/logs/consolelogs/rocketmq-console.log]
21:14:49,230 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
...
21:14:49,232 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@91161c7 - Registering current configuration as safe fallback point
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.0)

[2022-05-04 21:14:50.147] INFO background-preinit - HV000001: Hibernate Validator 6.2.0.Final
[2022-05-04 21:14:50.194] INFO main - Starting App v1.0.1-SNAPSHOT using Java 17.0.2 on user with PID 16344 (D:\rocketmq-dashboard\target\rocketmq-dashboard-1.0.1-SNAPSHOT.jar started by user in D:\rocketmq-dashboard)
[2022-05-04 21:14:50.205] INFO main - No active profile set, falling back to default profiles: default
[2022-05-04 21:14:52.633] INFO main - setNameSrvAddrByProperty nameSrvAddr=127.0.0.1:9876
[2022-05-04 21:14:53.088] INFO main - Tomcat initialized with port(s): 8080 (http)
[2022-05-04 21:14:53.106] INFO main - Initializing ProtocolHandler ["http-nio-8080"]
[2022-05-04 21:14:53.107] INFO main - Starting service [Tomcat]
[2022-05-04 21:14:53.109] INFO main - Starting Servlet engine: [Apache Tomcat/9.0.55]
...
[2022-05-04 21:15:00.255] INFO scheduling-1 - create MQuser instance ClientConfig [namesrvAddr=127.0.0.1:9876, clientIP=192.168.245.1, instanceName=1651670100054, clientCallbackExecutorThreads=4, pollNameServerInterval=30000, heartbeatBrokerInterval=30000, persistConsumerOffsetInterval=5000, pullTimeDelayMillsWhenException=1000, unitMode=false, unitName=null, vipChannelEnabled=true, useTLS=false, language=JAVA, namespace=null, mqClientApiTimeout=3000] success.

访问如下地址进入web管理界面:

http://127.0.0.1:8080/

02 官方文档

rocketmq官方中文文档:

https://github.com/apache/rocketmq-externals/blob/master/docs/connect/cn/README.md

rocketmq快速启动:

https://rocketmq.apache.org/docs/quick-start/

rocketmq下载:

https://rocketmq.apache.org/dowloading/releases/

持续更新中…