消息队列-RocketMQ

一.概述

  1. 大多数应用中,都可以通过消息服务中间件的方式来提升系统的异步通信、扩展解耦能力
  2. 消息服务中两个重要的概念:消息代理(Message broker)目的地(destination),当消息发送者发送消息之后,将有消息代理接管,消息代理保证消息传递到指定的目的地。
  3. 消息队列主要由两种形式的目的地,队列(queue):点对点消息通信;主题(topic):发布(publish)和订阅(subscribe)消息通信。

二.RocketMQ

1、RocketMQ简介

RocketMQ是一个纯Java、分布式、队列模型的开源消息中间件,前身是MetaQ,是阿里参考Kafka特点研发的一个队列模型的消息中间件,后开源给apache基金会成为了apache的*开源项目,具有高性能、高可靠、高实时、分布式特点。

2、RocketMQ下载安装(windows和linux基本相同)

1.下载地址

https://github.com/apache/rocketmq/releases

2.环境要求

64bit OS, Linux/Unix/Mac is recommended;(Windows user see guide below)
64bit JDK 1.8+;
Maven 3.2.x;
Git;
4g+ free disk for Broker server

3.解压安装

进入主目录预编译

cd /rocketmq/rocketmq-rocketmq-all-4.9.0
mvn -Prelease-all -DskipTests clean install -U

需要下载的挺多的。

4.搬移

将maven解压打的包挪到常用路径下

cd /rocketmq/rocketmq-rocketmq-all-4.9.0/distribution/target/rocketmq-4.9.0
mv rocketmq-4.9.0/ /usr/local/ 

5.bin路径文件

-rwxr-xr-x 1 root root 1654 Jun 21 21:49 cachedog.sh
-rwxr-xr-x 1 root root  845 Jun 21 21:49 cleancache.sh
-rwxr-xr-x 1 root root 1116 Jun 21 21:49 cleancache.v1.sh
drwxr-xr-x 2 root root 4096 Jun 21 21:49 dledger
-rwxr-xr-x 1 root root 1400 Jun 21 21:49 mqadmin
-rwxr-xr-x 1 root root 1029 Jun 21 21:49 mqadmin.cmd
-rwxr-xr-x 1 root root 1394 Jun 21 21:49 mqbroker
-rwxr-xr-x 1 root root 1084 Jun 21 21:49 mqbroker.cmd
-rwxr-xr-x 1 root root 1373 Jun 21 21:49 mqbroker.numanode0
-rwxr-xr-x 1 root root 1373 Jun 21 21:49 mqbroker.numanode1
-rwxr-xr-x 1 root root 1373 Jun 21 21:49 mqbroker.numanode2
-rwxr-xr-x 1 root root 1373 Jun 21 21:49 mqbroker.numanode3
-rwxr-xr-x 1 root root 1396 Jun 21 21:49 mqnamesrv
-rwxr-xr-x 1 root root 1088 Jun 21 21:49 mqnamesrv.cmd
-rwxr-xr-x 1 root root 1571 Jun 21 21:49 mqshutdown
-rwxr-xr-x 1 root root 1398 Jun 21 21:49 mqshutdown.cmd
-rwxr-xr-x 1 root root 2222 Jun 21 21:49 os.sh
-rwxr-xr-x 1 root root 1148 Jun 21 21:49 play.cmd
-rwxr-xr-x 1 root root 1008 Jun 21 21:49 play.sh
-rwxr-xr-x 1 root root  772 Jun 21 21:49 README.md
-rwxr-xr-x 1 root root 2230 Jun 21 21:49 runbroker.cmd
-rwxr-xr-x 1 root root 3734 Jun 21 21:49 runbroker.sh
-rwxr-xr-x 1 root root 1840 Jun 21 21:49 runserver.cmd
-rwxr-xr-x 1 root root 4048 Jun 21 21:49 runserver.sh
-rwxr-xr-x 1 root root 1156 Jun 21 21:49 setcache.sh
-rwxr-xr-x 1 root root 1408 Jun 21 21:49 startfsrv.sh
-rwxr-xr-x 1 root root 1634 Jun 21 21:49 tools.cmd
-rwxr-xr-x 1 root root 1903 Jun 21 21:49 tools.sh

6.启动

遇到问题:内存不足无法启动,修改runserver.sh配置文件

#JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
JAVA_OPT="${JAVA_OPT} -server -Xms500m -Xmx500m -Xmn500m -XX:PermSize=128m -XX:MaxPermSize=320m"

启动nameserver

./mqnamesrv

启动mqbroker(同样要求改配置,这个默认的更大)

./mqbroker

7.测试

./tools.sh org.a[ache.rocketmq.example.quickstart.Producer

遇到异常1:发送失败提示

java.lang.IllegalStateException: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to null failed

在tools脚本中添加

export NAMESRV_ADDR=localhost:9876

遇到异常2:Broker没有连接到Server

No route info of this topic: TopicTest

重新启动broker,并且指定IP:端口

./mqbroker -n localhost:9876

8.rocketmq-externals

上一篇:HCNA Routing&Switching之vrp文件系统


下一篇:【AI视野·今日Robot 机器人论文速览 第八期】Wed, 16 Jun 2021