mqtt协议的中间件有很多,例如 Mosquitto、RabbitMQ、ActiveMQ、ZeroMQ 等等

今天我主要介绍 ActiveMQ 的安装和使用

ActiveMQ的安装

下载地址

http://activemq.apache.org/components/classic/download/

windows 下安装

  1. 下载 apache-activemq-5.15.10-bin.zip 压缩包
  2. 解压压缩包 apache-activemq-5.15.10-bin.zip 得到解压后目录 apache-activemq-5.15.10\bin\win64
  3. 进入到apache-activemq-5.15.10\bin\win64目录 双击启动 activemq.bat 启动服务
  4. 访问浏览器 http://127.0.0.1:8161/admin/ 表示成功

Linux 下安装

  1. 下载文件 apache-activemq-5.15.10-bin.tar.gz 压缩包
  2. 将下载的文件上传到服务器
  3. 解压压缩包 tar -zxvf apache-activemq-5.15.10-bin.tar.gz 得到 apache-activemq-5.15.10 目录
  4. 进入到apache-activemq-5.15.10\bin目录,执行命令 ./activemq start 启动服务
  5. 设置开机自启
1
2
3
4
5
6
7
8
9
10
11
12
建立软连接
ln -s /root/apache-activemq-5.15.10/bin/activemq /etc/init.d

设置开启启动
chkconfig activemq on



通过系统指令
service activemq start
service activemq status
service activemq stop
  1. 访问浏览器 http://服务器IP:8161/admin/ 表示成功

liunx 下docker 部署服务

  1. 执行docker 启动容器命令
1
2
3
docker run -p 61616:61616 -p 8161:8161 -p 1883:1883 -p 61614:61614 -p 61613:61613 -p 5672:5672 \
-v /your/persistent/dir/conf:/opt/activemq/conf \
rmohr/activemq
  1. 访问浏览器 http://服务器IP:8161/admin/ 表示成功

linux docker-compose 部署服务

  1. docker-compse.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
version: "3"
services:
activemq:
restart: always
container_name: activemq
image: rmohr/activemq
ports:
- 61616:61616
- 60613:61613
- 60614:61614
- 1883:1883
- 8161:8161
volumes:
- /usr/local/docker/activeMQ/conf:/opt/activemq/conf
  1. 启动docker 容器 docker-compose up -d
  2. 访问浏览器 http://服务器IP:8161/admin/ 表示成功

ActiveMQ 使用

apache-activemq-5.15.10/examples 目录里面有各种使用案例,可以逐一查看,然后我这边主要是讲讲MQTT的连接

具体后续跟进