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 创建配置类 ...
随机推荐
- 从头开始学eShopOnContainers——设置WebSPA单页应用程序
一.简介 Web SPA单页应用程序需要一些额外的步骤才能使其工作,因为它需要在生成Docker镜像之前构建JavaScript框架依赖项和JS代码. 二.安装基础环境 1.安装NPM 为了能够使用n ...
- 个人JS体系整理(三)
一. 严格模式 JavaScript 严格模式(strict mode)即在严格的条件下运行.首先声明,严格模式是ES5中提出来的,准确来说就是一句指令Use strict,它的目的是指定代码在严格条 ...
- windows10 docker 使用以及虚拟机下fastDFS 的使用教程
我们 先来了解下 什么是docker? Docker的思想来自于集装箱,集装箱解决了什么问题?在一艘大船上,可以把货物规整的摆放起来.并且各种各样的货物被集装箱标准化了,集装箱和集装箱之间不会互相 ...
- 用shell脚本安装apache
我们首先创建一个文件为test.sh,执行此文件的方法有以下四种方式: 1../test.sh(必须chmod赋予执行权限) 2.. test.sh 3.sourse test.sh 4.[shell ...
- how to use windows azure market
here is the sample. namespace USCrime2006and2007 { class Program { static void Main(string[] args) { ...
- vue is detected
Vue.js is detected on this page. Devtools inspection is not available because it's in production mod ...
- redux超易学三篇之三(一个逻辑完整的react-redux)
配合源代码学习吧~ : 我是源代码 这一分支讲的是 如何完整地(不包含优化,也没有好看的页面) 搭建一个 增删改查 的 react-redux 系统 不同于上一节的 react-redux,这里主要采 ...
- flask-restful基础
flask-restful基本使用 基本使用 from flask_restful import Api,Resource,reqparse,inputs from flask import Flas ...
- [SP1825] Free tour II
/* ----------------------- [题解] https://www.luogu.org/blog/IRving1-1/solution-sp1825 --------------- ...
- JAVA数据结构--希尔排序
希尔排序通过将比较的全部元素分为几个区域来提升插入排序的性能.这样可以让一个元素可以一次性地朝最终位置前进一大步.然后算法再取越来越小的步长进行排序,算法的最后一步就是普通的插入排序,但是到了这步,需 ...