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. SaltStack配置管理-LAMP状态设计

    上一篇:SaltStack之Salt-ssh 配置文件模板 apache: pkg.installed: - name: httpd service.running: - name: httpd /e ...

  2. Python全栈day28(描述符应用)

    描述符的使用 python是弱类型语言,及参数的赋值没有类型限制,下面通过描述符机制来实现类型限制功能 描述符应用1.py class Typed: def __get__(self, instanc ...

  3. java递归构建菜单树

    package testSimple; import java.util.ArrayList; import java.util.List; public class BuildTree { publ ...

  4. mysql - json - look up subobjects or nested values directly by key or array index without reading all values

    w https://dev.mysql.com/doc/refman/5.7/en/json.html

  5. LInux进程虚拟地址空间的管理

    2017-04-07 脱离物理内存的管理,今天咱们来聊聊进程虚拟内存的管理.因为进程直接分配和使用的都是虚拟内存,而物理内存则是有系统“按需”分配给进程,在进程看来,只知道虚拟内存的存在! 前言: 关 ...

  6. spring MVC中的异常统一处理

    1.spring MVC中定义了一个标准的异常处理类SimpleMappingExceptionResolver 该类实现了接口HandlerExceptionResolver 2.看下SimpleM ...

  7. Oracle 常见问题汇总

    1.Listener refused the connection with the following error 安装之后如果遇到如下问题状态: 失败 -测试失败: Listener refuse ...

  8. Jquery源码分析(一)

    版本: jQuery JavaScript Library v3.2.1 分析架构: 打开jquery.js,哇塞,一万多行,噩梦啊!很多人就say bye-bye了.其实,将代码结构拆分后,再分析源 ...

  9. pycharm使用技巧。(mac版本)

    一.pycharm使用中的一些快捷键 1.cmd  + b 跳转到声明处(cmd加鼠标) 2.option + c 复制光标当前行,剪切同理 3.option + v 粘贴复制的行 4.option ...

  10. boost circular buffer环形缓冲类

    Boost.Circular_buffer维护了一块连续内存块作为缓存区,当缓存区内的数据存满时,继续存入数据就覆盖掉旧的数据. 它是一个与STL兼容的容器,类似于 std::list或std::de ...