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 应用的初始搭建以及开发过程. 该框架使用了特定的方 ...
随机推荐
- Hibernate-sessio缓存的操作
首先咋们看一个图: flush:首先箭头是由缓存指向数据库,即当我调用 Session.flush()方法时它会强制使数据库的记录跟缓存 中的对象状态保持同步 ,如果不一致,就会发送Sql语句 ,保持 ...
- Python全栈day14-15-16-17(函数)
一,数学定义的函数 函数的定义:给定一个数集A,对A施加对应法则f,记作f(A),得到另一数集B,也就是B=f(A).那么这个关系式就叫函数关系式,简称函数.函数概念含有三个要素:定义域A.值域C和对 ...
- Elastic Load Balancing with Sticky Sessions
Elastic Load Balancing with Sticky Sessions — Shlomo Swidler https://shlomoswidler.com/2010/04/elast ...
- [genome shell]标题栏优化
参考地址:https://wiki.archlinux.org/index.php/GNOME_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)#.E4.BB.8E.E5. ...
- BitTrex行情查看与技术指标系统
上个月的时候,向TradingView申请K线图行情插件,填了各种资料,被问了N多问题,结果却仍是不愿意提供插件给我们. 于是,我们自己开发了一个BitTre行情查看与技术指标系统, 这套系统被国内多 ...
- CSS冲突1 要关掉的css在项目内:【material-table】 中 checkbox 点击checkbox无法选中or取消,点击旁边才能选中or取消
CSS优先级: !important > 行内样式 > 内嵌样式|链接外部样式(哪个在后面哪个优先级大) id选择器 > class选择器 > 元素选择器 react中好像还不 ...
- python学习笔记(十九)发送邮件
在python开发项目或者做自动化测试时候,在测试完成后需要将测试结果总结后进行上报,那么我们就可以通过发送邮件来完成这项工作. 下面我们来看看python中怎么发送邮件的,python中发送邮件可以 ...
- hadoop-3.0.0-beta1分布式安装
楼主是从Hadoop2.x版本过来的,在工作之余自己搭建了一套3.0的版本来耍一耍,此文章的前置环境准备工作省略.主要介绍一些和Hadoop2.x版本不同的安装之处 Hadoop版本:hadoop-3 ...
- 记一次服务器迁移 TFS客户端ip更换
服务器迁移,TFS服务端IP由原10.58.8.231更换至10.58.1.230 TFS客户端更换ip操作比较复杂,请谨慎操作,避免脱库的风险!!! 打开注册表,运行->regedit 找到H ...
- spark-streaming读kafka数据到hive遇到的问题
在项目中使用spark-stream读取kafka数据源的数据,然后转成dataframe,再后通过sql方式来进行处理,然后放到hive表中, 遇到问题如下,hive-metastor在没有做高可用 ...