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 创建配置类 ...
随机推荐
- FTP文件上传以及获取ftp配置帮助类
帮助类: using QSProjectBase; using Reform.CommonLib; using System; using System.Collections.Generic; us ...
- 《C#多线程编程实战》2.7 CountDownEvent
这个同步线程的类大概是东北的. 很有意思. 会限定你的线程使用的次数,更形象一点的像是你妈,提前准备好你要使用的线程的次数,用不完还不高兴那种的. 使用顺序基本就是 实例化 填充线程的启动次数 使用 ...
- appstore开发者 名称修改
1.前提是开发者账号为企业账号 CSDN大佬写的,应该没错
- cp命令覆盖不提示
参数说明 -i, --interactive prompt before overwrite (overrides a previous -n option) #文件存在是,交互式提示是否覆盖 - ...
- CBoard 看板参数管理
看板设计采用简单Row+Column布局模式,每行总长度为12,每列对应一个图表,行高度可以调节,列高度集成行高 左边栏看板分类中,我的看板为当前用户创建的看板,普通看板分类通过分类管理维护,保存看板 ...
- ARKit的使用
//创建场景 let scene = SCNScene() /* //1.几何 let box = SCNBox.init(width: 0.1, height: 0.1, length: 0.1, ...
- 使用navicat将mysql转换成sqlserver
使用navicat将mysql转换成sqlserver 1. 打开navicat,连接所需要装换的mysql数据库. 2. 选择所需要转换的数据源,点击右键选择数据传输.如图: 3. 打开数据传输面板 ...
- Python + gevent模块对单个接口进行并发测试 1
本文知识点 利用gevent模块进行并发测试 代码如下 from gevent import monkey monkey.patch_all() import requests import geve ...
- hexo 博客
梦飞扬~ 个人网站:Mauger`s Blog 博客园 标签 新随笔 随笔 管理 Github 随笔 - 61 文章 - 1 评论 - 0 使用Node.js+Hexo+Github搭建个人博客 ...
- C++_友元3-其他友元关系
友元和类的关系还可以更复杂. 举个例子,假设出现了交互式遥控器,交互式遥控器能够让您回答电视节目中的问题,如果回答错误,电视将在控制器上产生嗡嗡声. 这个例子的问题,可以使用新的友元关系来解决.我把它 ...