SpringBoot 简单集成ActiveMQ
ActiveMQ安装配置步骤见:https://www.cnblogs.com/vincenshen/p/10635362.html
第一步,pom.xml引入ActiveMQ依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
第二步,application.properties中配置activemq
spring.activemq.broker-url=tcp://172.16.65.243:61616
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
spring.activemq.user=admin
spring.activemq.password=admin
第三步,Producer类编写
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import java.util.HashMap;
import java.util.Map; @Component
public class Producer { @Autowired
private JmsMessagingTemplate jmsMessagingTemplate; @Scheduled(fixedRate = 2000) // 使用定时任务,每两秒向mq中发送一个消息
public void sendMsg(){
Map<String, String> ptpMap = new HashMap<>();
ptpMap.put("hello", "activeMQ");
jmsMessagingTemplate.convertAndSend("ptp", ptpMap);
}
}
第四步,Consumer编写
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component; import java.util.Map; @Component
public class Consumer { @JmsListener(destination = "ptp") // 通过JmsListerner实时获取mq中的消息
public void readMsg(Map map){
System.out.println("currentTimeMillis" + System.currentTimeMillis() + "::ptp = [" + map + "]");
}
}
第五步,测试效果
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE) 2019-04-01 14:37:30.686 INFO 71766 --- [ main] c.v.v.VcenterEventApplication : Starting VcenterEventApplication on shongbing-a01.vmware.com with PID 71766 (/Users/shongbing/Downloads/vcenter_event/target/classes started by shongbing in /Users/shongbing/Downloads/vcenter_event)
2019-04-01 14:37:30.689 INFO 71766 --- [ main] c.v.v.VcenterEventApplication : No active profile set, falling back to default profiles: default
2019-04-01 14:37:31.564 INFO 71766 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2019-04-01 14:37:31.755 INFO 71766 --- [ main] c.v.v.VcenterEventApplication : Started VcenterEventApplication in 1.422 seconds (JVM running for 2.162)
currentTimeMillis1554100651824::ptp = [{hello=activeMQ}]
currentTimeMillis1554100651828::ptp = [{hello=activeMQ}]
currentTimeMillis1554100653755::ptp = [{hello=activeMQ}]
currentTimeMillis1554100655755::ptp = [{hello=activeMQ}]
currentTimeMillis1554100657755::ptp = [{hello=activeMQ}]
currentTimeMillis1554100659757::ptp = [{hello=activeMQ}]
SpringBoot 简单集成ActiveMQ的更多相关文章
- Springboot简单集成ActiveMQ
Springboot简单集成ActiveMQ 消息发送者的实现 pom.xml添加依赖 <dependency> <groupId>org.springframework.bo ...
- springboot 简单使用 activemq 接收消息
1.在pom.xml 加入配置文件 <dependency> <groupId>org.springframework.boot</groupId> <art ...
- SpringBoot集成ActiveMQ
前面提到了原生API访问ActiveMQ和Spring集成ActiveMQ.今天讲一下SpringBoot集成ActiveMQ.SpringBoot就是为了解决我们的Maven配置烦恼而生,因此使用S ...
- 从零开始学 Java - Spring 集成 ActiveMQ 配置(二)
从上一篇开始说起 上一篇从零开始学 Java - Spring 集成 ActiveMQ 配置(一)文章中讲了我关于消息队列的思考过程,现在这一篇会讲到 ActivMQ 与 Spring 框架的整合配置 ...
- springboot elasticsearch 集成注意事项
文章来源: http://www.cnblogs.com/guozp/p/8686904.html 一 elasticsearch基础 这里假设各位已经简单了解过elasticsearch,并不对es ...
- Springboot Application 集成 OSGI 框架开发
内容来源:https://www.ibm.com/developerworks/cn/java/j-springboot-application-integrated-osgi-framework-d ...
- 以ActiveMQ为例JAVA消息中间件学习【3】——SpringBoot中使用ActiveMQ
前言 首先我们在java环境中使用了ActiveMQ,然后我们又在Spring中使用了ActiveMQ 本来这样已经可以了,但是最近SpringBoot也来了.所以在其中也需要使用试试. 可以提前透露 ...
- 【ActiveMQ】Spring Jms集成ActiveMQ学习记录
Spring Jms集成ActiveMQ学习记录. 引入依赖包 无论生产者还是消费者均引入这些包: <properties> <spring.version>3.0.5.REL ...
- springboot简单介绍
1.springboot简单介绍 微服务架构 Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程. 该框架使用了特定的方 ...
随机推荐
- QBC检索和本地SQL检索
细说QBC:QBC(Query By Criteria) 查询:这种方式比较面向对象方式,因为是面向对象,所以查询时参数名就是所查询的类的属性名并不是数据库的表的列名重点是有三个描述条件的对象:Res ...
- 十个技巧迅速提升JQuery性能
本文提供即刻提升你的脚本性能的十个步骤.不用担心,这并不是什么高深的技巧.人人皆可运用!这些技巧包括: 使用最新版本 合并.最小化脚本 用for替代each 用ID替代class选择器 给选择器指定前 ...
- android开发笔记(一)Android studio 输入法
以前都是用的时候查资料做些增添即可,现在下决心系统学习下. 首先发现developer.Android.com在开发工具上开始推出了 Android Studio了,不过他自己没有sdk manage ...
- JMeter场景运行(非GUI方式运行命令)
JMeter场景运行方式可分为两种: GUI方式运行,视窗运行,双击jmeter.bat启动运行即可以看到运行界面: 非GUI方式运行,在命令窗口中使用java –jar命名运行: 但不管是以 ...
- Amr and Chemistry---cf558C(暴力,加技巧)
题目链接:http://codeforces.com/problemset/problem/558/C 题意:有n个数,每个数都可以进行两个操作 *2 或者 /2,求最小的操作次数和,使得所有的数都相 ...
- icomoon.io生成字体图标
1. 准备svg图片 2. 打开icomoon选择icomoon App 3. import icons 上传本地的svg图片 4. 点击选中以后点击generate fonts形成字体图标 5. p ...
- C#建WindowForm调用R可视化
众所周知R软件功能非常强大,可以很好的进行各类统计,并能输出图形.下面介绍一种R语言和C#进行通信的方法,并将R绘图结果显示到WinForm UI界面上的方法,文中介绍的很详细,需要的朋友可以参考下. ...
- Web爬虫的C#请求发送
public class HttpControler { //post请求发送 private Encoding m_Encoding = Encoding.GetEncoding("gb2 ...
- 注册表REG文件编写大全
Windows 中的注册表文件( system.dat 和 user.dat )是 Windows 的核心数据库,因此,对 Windows 来说是非常重要的. 通过修改注册表文件中的数据,可以达到优化 ...
- Linux系统性能调优之性能分析
1.Linux性能分析的目的1)找出系统性能瓶颈(包括硬件瓶颈和软件瓶颈):2)提供性能优化的方案(升级硬件?改进系统系统结构?):3)达到合理的硬件和软件配置:4)使系统资源使用达到最大的平衡.(一 ...