RocketMQ(一)

主要内容

  • 编译安装
  • HelloWorld

官方网站

http://rocketmq.apache.org/

Github

https://github.com/apache/rocketmq

Quick Start

在 Linux 上安装 JDK

1
2
3
4
5
6
7
8
9
10
11
12
yum search jdk

yum install java-1.8.0-openjdk.x86_64

# 找到安装位置
java -verbose

[Loaded java.lang.Shutdown from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/lib/rt.jar]
[Loaded java.lang.Shutdown$Lock from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/lib/rt.jar]

# 配置 JAVA_HOME
vim /etc/profile

在 Linux 上安装 Maven

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 下载压缩包
wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

# 解压
tar -zxvf apache-maven-3.6.3-bin.tar.gz

mv apache-maven-3.6.3 /usr/local/

vim /usr/local/apache-maven-3.6.3/conf/settings.xml
<mirror>
<id>aliyun-maven</id>
<mirrorOf>*</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

vim /etc/profile
export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=$PATH:$MAVEN_HAOM/bin

source /etc/profile

安装 RocketMQ

1
2
3
4
5
6
7
8
9
10
11
12
wget https://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.8.0/rocketmq-all-4.8.0-source-release.zip

unzip rocketmq-all-4.8.0-source-release.zip

mvn -Prelease-all -DskipTests clean install -U

# 启动
./mqnamesrv
./mqbroker

# 测试
./tools.sh org.apache.rocketmq.example.quickstart.Producer

若遇到错误:linux No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK,则执行以下命令

1
yum install java-devel

启动报错:Native memory allocation (mmap) failed to map 2147483648 bytes for committing reserved memory

1
2
3
4
5
6
vim /usr/local/rocketmq-4.8.0/bin/runserver.sh
vim /usr/local/rocketmq-4.8.0/bin/runbroker.sh

JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
# 改为
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

测试报错:connect to null failed

1
2
3
4
vim tools.sh

# 放在 JVM Configuration 之前
export NAMESRV_ADDR=localhost:9876

测试报错:org.apache.rocketmq.client.exception.MQClientException: No route info of this topic: TopicTest

1
2
# 启动broker指定连接的ip:port
./mqbroker -n localhost:9876

控制台rocketmq-console编译安装

下载

github仓库

编译

1
mvn clean package -Dmaven.test.skip=true

启动

1
java -jar rocketmq-console-ng-2.0.0.jar --rocketmq.config.namesrvAddr=172.17.0.2:9876