springboot整合activeMq 跳坑
安装
activeMq 安装请看我的另一篇https://www.cnblogs.com/milicool/p/8420926.html
版本
springboot 2.0.5.RELEASE
项目结构

POM.xml
我这里开启了activemq连接池, 毕竟管理一下连接才更合理
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5
6 <groupId>com.activemq</groupId>
7 <artifactId>demo</artifactId>
8 <version>0.0.1-SNAPSHOT</version>
9 <packaging>jar</packaging>
10
11 <name>demo</name>
12 <description>Demo project for Spring Boot activeMq</description>
13
14 <parent>
15 <groupId>org.springframework.boot</groupId>
16 <artifactId>spring-boot-starter-parent</artifactId>
17 <version>2.0.5.RELEASE</version>
18 <relativePath/> <!-- lookup parent from repository -->
19 </parent>
20
21 <properties>
22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24 <java.version>1.8</java.version>
25 </properties>
26
27 <dependencies>
28 <dependency>
29 <groupId>org.springframework.boot</groupId>
30 <artifactId>spring-boot-starter-activemq</artifactId>
31 </dependency>
32 <dependency>
33 <groupId>org.springframework.boot</groupId>
34 <artifactId>spring-boot-starter-web</artifactId>
35 </dependency>
36
37 <dependency>
38 <groupId>org.springframework.boot</groupId>
39 <artifactId>spring-boot-starter-test</artifactId>
40 <scope>test</scope>
41 </dependency>
42
43 <!-- activemq连接池 -->
44 <dependency>
45 <groupId>org.apache.activemq</groupId>
46 <artifactId>activemq-pool</artifactId>
47 <version>5.14.5</version>
48 </dependency>
49
50 <!-- fastjson -->
51 <dependency>
52 <groupId>com.alibaba</groupId>
53 <artifactId>fastjson</artifactId>
54 <version>1.2.38</version>
55 </dependency>
56 </dependencies>
57
58 <build>
59 <plugins>
60 <plugin>
61 <groupId>org.springframework.boot</groupId>
62 <artifactId>spring-boot-maven-plugin</artifactId>
63 </plugin>
64 </plugins>
65 </build>
66 </project>
application.yml

生产者
1 /**
2 * 生产者
3 * @author milicool
4 * Created on 2018/9/13
5 */
6 @Service
7 public class Producer {
8
9 /** JmsMessagingTemplate是对jmsTemplate的封装 */
10 @Autowired
11 private JmsMessagingTemplate jmsTemplate;
12
13 /** 这里参数用Queue更好 */
14 public void sendTestMessage(Queue queue, final String message) {
15 jmsTemplate.convertAndSend(queue, message);
16 }
17 }
消费者
测试类
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
private Logger log = LoggerFactory.getLogger(DemoApplicationTests.class); @Autowired
private Producer producer; @Test
public void contextLoads() {
Queue queue = new ActiveMQQueue("spring_queue_test");
for (int i = 0; i < 5; i++) {
String msg = "hello world, 序号: " + i;
producer.sendTestMessage(queue, msg);
log.info("发送队列, msg: {}" + msg);
}
}
}
结果

感谢观看哦

springboot整合activeMq 跳坑的更多相关文章
- Web项目容器集成ActiveMQ & SpringBoot整合ActiveMQ
集成tomcat就是随项目启动而启动tomcat,最简单的方法就是监听器监听容器创建之后以Broker的方式启动ActiveMQ. 1.web项目中Broker启动的方式进行集成 在这里采用Liste ...
- SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...
- SpringBoot整合ActiveMQ快速入门
Spring Boot 具有如下特性: 为基于 Spring 的开发提供更快的入门体验 开箱即用,没有代码生成,也无需 XML 配置.同时也可以修改默认值来满足特定的需求. 提供了一些大型项目中常见的 ...
- 解决Springboot整合ActiveMQ发送和接收topic消息的问题
环境搭建 1.创建maven项目(jar) 2.pom.xml添加依赖 <parent> <groupId>org.springframework.boot</group ...
- SpringBoot整合ActiveMQ和开启持久化
一.点对点 1.提供者目录展示 2.导入依赖 <dependency> <groupId>org.springframework.boot</groupId> &l ...
- ActiveMQ 笔记(四)Spring\SpringBoot 整合 Activemq
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 一.Spring 整合Activemq 1.所需jar包 <dependencies> &l ...
- springboot整合ActiveMQ,配置问题
1.ActiveMQ的安装和相关配置修改 去官网下载安装包解压至文件夹 双击打开 打开浏览器输入 http://127.0.0.1:8161 到此activeMQ就安装好了 2.springboot工 ...
- SpringBoot整合ActiveMQ,看这篇就够了
ActiveMQ是Apache提供的一个开源的消息系统,完全采用Java来实现,因此它能很好地支持JMS(Java Message Service,即Java消息服务)规范:本文将详细介绍下Activ ...
- SpringBoot整合ActiveMQ发送邮件
虽然ActiveMQ以被其他MQ所替代,但仍有学习的意义,本文采用邮件发送的例子展示ActiveMQ 1. 生产者1.1 引入maven依赖1.2 application.yml配置1.3 创建配置类 ...
随机推荐
- Service Fabric 用 Powershell 部署应用到本地
前置说明 安装 Service Fabric SDK,会在本机 C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\Servic ...
- iOS应用打包完后再在开发者网站添加应用测试ID能够加入测试吗
1.明确指出 不行: 1.打包测试包前一定要先添加测试设备的UDID 2.添加测试的设备UDID一定要先于打包测试包,否则设备无法参加测试 3.使用蒲公英分享测试包,查看可参加测试的设备UDID 2. ...
- VSCode提示pylint isnot installed
1.下载所需扩展 在https://www.lfd.uci.edu/~gohlke/pythonlibs/中下载所需扩展,我下载的是:pylint-2.1.1-py2.py3-none-any.whl ...
- git you need to resolve your current index first 解决办法
当使用git checkout 切换分支时会提示you need to resolve your current index first,使用如下命令即可解决. $ git reset --merge
- Map/Reduce应用开发基础知识-摘录
Map/Reduce 这部分文档为用户将会面临的Map/Reduce框架中的各个环节提供了适当的细节.这应该会帮助用户更细粒度地去实现.配置和调优作业.然而,请注意每个类/接口的javadoc文档提供 ...
- jeesite 的提示消息图标
jeesite 的提示消息图标 jeesite 框架的提示信息 保存数据时 总是显示一个叉子图标 不符合要求 原因: 不加成功两字:如下 后来大神说 保存数据提示语句必须加“”“成功” 才会出现正确 ...
- 基于linux内核包过滤技术的应用网关
目录 基于linux内核包过滤技术的应用网关 硬件形态 基本原理 应用场景 主要功能 其他功能 客户定制 基于linux内核包过滤技术的应用网关 硬件形态 基本原理 应用场景 媒体内容过滤和深度识别 ...
- 【算法笔记】B1022 D进制的A+B
1022 D进制的A+B (20 分) 输入两个非负 10 进制整数 A 和 B (≤230−1),输出 A+B 的 D (1<D≤10)进制数. 输入格式: 输入在一行中依次给出 3 个 ...
- HDOJ3085 Nightmare II 双向BFS
重构一遍就A了...但这样效率太低了...莫非都要重构???QWQ 每一秒男同志bfs3层,女同志bfs1层.注意扩展状态时,要判一下合不合法再扩展,而不是只判扩展的状态合不合法,否则有可能由非法的走 ...
- HihoCoder - 1048 状压DP 经典题
hihocoder题解说的十分清晰了,这份代码就是从讲解里学习的 方案数就是不断枚举合法状态下横放竖放或两者均可 合法判断的依据是记录当前行和下一行的状态 防止重复枚举的方法是先按行后按列 递归基瞎写 ...