【springboot】之整合ActiveMQ
1、引入依赖的jar
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
</dependencies>
2、application配置
spring.activemq.broker-url=tcp://localhost:61616
spring.activemq.in-memory=true
spring.activemq.pool.enabled=true
3、单向发送消息
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MqApplication.class)
public class MqTest { @Autowired
JmsMessagingTemplate jmsMessagingTemplate; //发送String消息
@Test
public void testStr() {
//往luna队列发送消息
jmsMessagingTemplate.convertAndSend("luna","to luna queue");
}
}
接收消息
@Component
@Slf4j
public class Consumer {
@JmsListener(destination = "luna")
public void receiveQueue(String text){
log.info("receive:{}",text);
}
}
查看ActiveMQ控制台
控制台打印
4、双向发送消息
例如 A发送B消费 B消费完毕将结果放在某一个队列中,A再去消费
我们将上面代码继续改造一下
@Component
@Slf4j
public class Consumer { @JmsListener(destination = "luna")
@SendTo("luna_ret")//将消费结果返回
public String receiveQueue(String text){
log.info("receive:{}",text);
return "SUCCESS--"+text;
}
}
写一个消费luna_ret的queue
@Component
@Slf4j
public class ConsumerRet { @JmsListener(destination = "luna_ret")
public void receiveQueue(String text){
log.info("receive:{}",text);
}
}
ok,我们再执行上面的发送queues代码
ActiveMQ控制台显示
控制台日志显示
由上可知,
@SendTo 注解
可以将返回值发送到指定的queue
-----------------------------------------------
springboot整合ActiveMQ安全配置
【springboot】之整合ActiveMQ的更多相关文章
- springboot整合ActiveMQ,配置问题
1.ActiveMQ的安装和相关配置修改 去官网下载安装包解压至文件夹 双击打开 打开浏览器输入 http://127.0.0.1:8161 到此activeMQ就安装好了 2.springboot工 ...
- SpringBoot2.0源码分析(二):整合ActiveMQ分析
SpringBoot具体整合ActiveMQ可参考:SpringBoot2.0应用(二):SpringBoot2.0整合ActiveMQ ActiveMQ自动注入 当项目中存在javax.jms.Me ...
- 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 2.x (13):整合ActiveMQ
ActiveMQ5.x不多做介绍了,主要是SpringBoot的整合 特点: 1)支持来自Java,C,C ++,C#,Ruby,Perl,Python,PHP的各种跨语言客户端和协议 2)支持许多高 ...
- SpringBoot第二十一篇:整合ActiveMQ
作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/11190048.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言 前一章节中 ...
- 解决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 ...
随机推荐
- 多点搜的bfs
Problem L. 跑图Time limit: 1000msMemory limit: 65536KBDescription跑图是 RPG 游戏中很烦躁的事情.玩家需要跑到距离他最近的传送点的位置. ...
- xdoj 1067组合数学+动态规划 (一个题断断续续想了半年 233)
题目分析 : (8 4) 可以由(7 4),(6,4),( 4,4) 基础上转化 意味着一个新加入的元素可以按照它加入的方式分类,从而实现动态规划 核心:加入方式 新加入的元素构成转换环的元素个数(n ...
- P1220 关路灯 (区间dp)
题目链接:传送门 题目大意: 总共有N盏灯,老张从点C(1 ≤ C ≤ N)开始关灯(关灯不需要等待时间,C点的灯直接关掉),与此同时灯开始烧电(已知功率Pi). 老张每次可以往左走关最近的灯或者往右 ...
- 嵌套for
- XML映射配置文件
XML映射配置文件 http://www.mybatis.org/mybatis-3/configuration.html Type Handlers 类型处理器 每当MyBatis在Prepared ...
- Python-random 随机数模块
random 随机数模块格式: import random 引入随机模块文件 1 import random 2 3 print(random.random())#(0,1)----float 大于0 ...
- crash - JNI WARNING: input is not valid modified utf-8: illegal continuation byte
the key point is "Modified UTF-8" is not like "Regular UTF-8", a legal Rgular UT ...
- LG4091 【[HEOI2016/TJOI2016]求和】
前置:第二类斯特林数 表示把\(n\)个小球放入\(m\)个不可区分的盒子的方案数 使用容斥原理分析,假设盒子可区分枚举至少有几个盒子为空,得到通项: \[S(n,m)=\frac{1}{m!}\su ...
- 安装Centos7时提示 /dev/root does not exits
安装centos 7时提示 "Warning: /dev/root does not exist, could not boot" 这个问题是木有找到你的U盘. 在一个能够编辑U盘 ...
- 基于lfslivecd-x86-6.3-r2145安装vnc和qemu
文章目录 把lfslivecd复制到硬盘上使用 编译安装vnc 前后下载了多个软件包进行编译安装 编译VNC 启动VNC 编译安装qemu 启动VNC客户端并连接虚拟机的vncviewer 把lfsl ...