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的更多相关文章

  1. Springboot简单集成ActiveMQ

    Springboot简单集成ActiveMQ 消息发送者的实现 pom.xml添加依赖 <dependency> <groupId>org.springframework.bo ...

  2. springboot 简单使用 activemq 接收消息

    1.在pom.xml 加入配置文件 <dependency> <groupId>org.springframework.boot</groupId> <art ...

  3. SpringBoot集成ActiveMQ

    前面提到了原生API访问ActiveMQ和Spring集成ActiveMQ.今天讲一下SpringBoot集成ActiveMQ.SpringBoot就是为了解决我们的Maven配置烦恼而生,因此使用S ...

  4. 从零开始学 Java - Spring 集成 ActiveMQ 配置(二)

    从上一篇开始说起 上一篇从零开始学 Java - Spring 集成 ActiveMQ 配置(一)文章中讲了我关于消息队列的思考过程,现在这一篇会讲到 ActivMQ 与 Spring 框架的整合配置 ...

  5. springboot elasticsearch 集成注意事项

    文章来源: http://www.cnblogs.com/guozp/p/8686904.html 一 elasticsearch基础 这里假设各位已经简单了解过elasticsearch,并不对es ...

  6. Springboot Application 集成 OSGI 框架开发

    内容来源:https://www.ibm.com/developerworks/cn/java/j-springboot-application-integrated-osgi-framework-d ...

  7. 以ActiveMQ为例JAVA消息中间件学习【3】——SpringBoot中使用ActiveMQ

    前言 首先我们在java环境中使用了ActiveMQ,然后我们又在Spring中使用了ActiveMQ 本来这样已经可以了,但是最近SpringBoot也来了.所以在其中也需要使用试试. 可以提前透露 ...

  8. 【ActiveMQ】Spring Jms集成ActiveMQ学习记录

    Spring Jms集成ActiveMQ学习记录. 引入依赖包 无论生产者还是消费者均引入这些包: <properties> <spring.version>3.0.5.REL ...

  9. springboot简单介绍

    1.springboot简单介绍 微服务架构 Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程. 该框架使用了特定的方 ...

随机推荐

  1. 飘城旅游网pc,流式,响应式布局

    相关视频教程http://pan.baidu.com/s/1o77wirK 我的源码链接:http://pan.baidu.com/s/1czTsKI

  2. Java 之NIO

    1. NIO 简介 Java NIO(New IO)是从1.4版本开始引入的一个新的IO API,可以替代标准的Java IO API; NIO 与原来的IO有同样的作用和目的,但是使用的方式完全不同 ...

  3. 重点:怎样正确的使用QThread类(很多详细例子的对比,注意:QThread 中所有实现的函数是被创建它的线程来调用的,不是在线程中)good

    背景描述: 以前,继承 QThread 重新实现 run() 函数是使用 QThread唯一推荐的使用方法.这是相当直观和易于使用的.但是在工作线程中使用槽机制和Qt事件循环时,一些用户使用错了.Qt ...

  4. cpython解释器内存机制

    java虚拟机内存 笼统分为两部分:堆区,栈区 其中,引用在栈区,对象在堆区 详细分为五部分:堆区,虚拟机栈区,本地方法栈区,方法区,程序计数器 cpython解释器内存 笼统分为两部分:堆区,栈区 ...

  5. 兼容获取scrollTop和scrollLeft(被滚动条卷走的部分)

    function scroll() { //ie9+ 标准浏览器 if (window.pageYOffset != null) { return { left: window.pageXOffset ...

  6. 浅析Android View(二)

    深入理解Android View(一) View的位置參数信息 二.View的绘制过程 View的绘制过程一共分为三个部分: - measure(測量View的大小) - layout(确定View的 ...

  7. Unity3D优化技巧系列七

    笔者介绍:姜雪伟,IT公司技术合伙人.IT高级讲师,CSDN社区专家,特邀编辑.畅销书作者,国家专利发明人;已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D ...

  8. C# 中利用 Conditional 定义条件方法

    利用 Conditional 属性,程序员可以定义条件方法.Conditional 属性通过测试条件编译符号来确定适用的条件.当运行到一个条件方法调用时,是否执行该调用,要根据出现该调用时是否已定义了 ...

  9. 文件传输(xmodem协议)

    https://www.menie.org/georges/embedded/ 需要移植如下两个基础的硬件读写函数 int _inbyte(unsigned short timeout); void ...

  10. SDUT3146:Integer division 2(整数划分区间dp)

    题目:传送门 题目描述 This is a very simple problem, just like previous one. You are given a postive integer n ...