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 创建配置类 ...
随机推荐
- 关于C#中Timer定时器的重入问题解决方法(也适用于多线程)
项目中用到了定时器随着服务启动作定时任务,按指定的准点时间定时执行相关操作,但是在指定准点时间内我只想让它执行一次,要避免重入问题的发生. 首先简单介绍一下timer,这里所说的timer是指的Sys ...
- HTML4.0 需要掌握的主要内容
常用标签: <html></html> 创建一个HTML文档 <head></head> 设置文档标题和其它在网页中不显示的信息 <title&g ...
- Java面向对象之多态(向上、向下转型) 入门实例
一.基础概念 多态: 重点是对象的多态性.某一事物的多种体现形态. 多态的作用: 1.提高了代码的扩展性,后期出现的功能,可以被之前的程序所执行. 2.不能使用子类特有的功能.只能使用覆盖父类的功能. ...
- 【guava】对象处理
一,equals方法 我们在开发中经常会需要比较两个对象是否相等,这时候我们需要考虑比较的两个对象是否为null,然后再调用equals方法来比较是否相等,google guava库的com.goog ...
- Win7下C/C++跨平台开发工具IDE的安装之Eclipse-CDT
2. win7下安装Eclipse-CDT运行C/C++程序: 下载Eclipse-CDT 64位:http://www.eclipse.org/downloads/packages/release/ ...
- maven项目运行找不到类的错误
Maven项目 eclipse工具 错误: [INFO] -------------------------------------------------------------[ERROR] CO ...
- 在DZ 中 showmessage 中可以再次执行 JS
showmessage ( '登录', '', array (), array ( 'showdialog' => 0, ...
- Query on a tree II 倍增LCA
You are given a tree (an undirected acyclic connected graph) with N nodes, and edges numbered 1, 2, ...
- springmvc相关配置和用法
目录如下: 一.spring mvc 核心类与接口 二.spring mvc 核心流程图 三.spring mvc DispatcherServlet说明 四.spring mvc 父子上下文的说明 ...
- PIE SDK栅格拉伸渲染
1. 功能简介 栅格数据拉伸渲染是对指定的波段进行图像拉伸,并设置拉伸之后的颜色带,根据像元值和颜色带进行数据渲染. 2. 功能实现说明 2.1. 实现思路及原理说明 第一步 实例化拉伸渲染对象示例 ...