SpringBoot中使用ActiveMQ
2018-04-22 本文已影响0人
_emo_
1. 首先下载ActiveMQ,链接地址:http://activemq.apache.org/ ,在bin目录下启动

2. 成功启动后,我们可以通过 http://localhost:8161 来访问管理页面,连接消息服务器的地址为tcp://localhost:61616 ,默认用户名密码都为admin,可在如下文件中进行自定义

3. 接下来是SpringBoot连接ActiveMQ,
(1) 引入如下依赖
(2) 配置ActiveMQ 连接,本人使用虚拟机运行的ActiveMQ,故IP有变,本机启动IP为localhost(127.0.0.1)
至此配置完成,开始使用。
4. 发布&订阅
(1)发布消息
(2) 订阅消息
在pub/sub模式中, 对消息的监听需要对containerFactory进行以下配置:

完整订阅如下:

(3) 测试
运行测试程序,收到发出的消息 "Hello !"即成功。
4. 历史消息查看可访问 127.0.0.1:8161/admin/queues.jsp 即可。