springBoot配置activeMq点对点模式消费信息以及独占模式消费如何设置
1、在pom文件中引入对应jar包
<!--activeMQ start-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<!-- <version>5.7.0</version> -->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<!--activeMQ end-->
2、application.yml文件配置activemq;对于监听Listener使用注解的形式
#activeMQ的配置
activemq:
broker-url: tcp://localhost:61616
in-memory: true
pool:
enabled: false #如果此处设置为true,需要加如下的依赖包,否则会自动配置失败,报JmsMessagingTemplate注入失败
3、创建生产者类,生产者代码如下:
/**
* Created by Administrator on 2018/7/27.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootJmsApplicationTests {
@Test
public void contextLoads() throws InterruptedException, JMSException {
Destination destination = new ActiveMQQueue("queue_demo");
//创建与JMS服务的连接:ConnectionFactory被管理的对象,由客户端创建,用来创建一个连接对象
ConnectionFactory connectionfactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
//获取连接,connection一个到JMS系统提供者的活动连接
javax.jms.Connection connection = connectionfactory.createConnection();
//打开会话,一个单独的发送和接受消息的线程上下文
Session session =connection.createSession(false,Session.AUTO_ACKNOWLEDGE );
Queue queue = new ActiveMQQueue("queue_demo");
MessageProducer msgProducer = session.createProducer(queue);
Message msg = session.createTextMessage("文本1");
msgProducer.send(msg);
System.out.println("文本消息已发送");
}
}
4、编写消费者代码,代码如下:
/**
* Created by Administrator on 2018/7/27.
*/
@Component
public class Consumer2 {
// 使用JmsListener配置消费者监听的队列,其中text是接收到的消息
@JmsListener(destination = "queue_es")
public void receiveQueue(String mapStr) {
System.out.println("接受的消息:"+mapStr); }
}
5、运行生产者(本处是test注解的测试代码),直接运行,结果如下
发送端:
接收端:
ps:如果想设置为独占消息消费模式,只需将消费者的代码@JmsListener注解处修改为如下代码:
@JmsListener(destination = "queue_es?consumer.exclusive=true")
就可以设置此消费者为独占消息消费模式,队列里的任务会玩先后顺序被这个消费者处理掉
springBoot配置activeMq点对点模式消费信息以及独占模式消费如何设置的更多相关文章
- SpringBoot整合ActiveMq实现Queue和Topic两种模式(看不懂你来打我)
目录 一.前言 二.ActiveMq的下载和使用 三.依赖准备 四.yml文件配置 五.配置Bean 六.创建生产者(Queue+Topic) 七.创建消费者(Topic模式下) 八.测试结果(Top ...
- SpringBoot配置activemq消息队列
1.配置pom相关依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...
- SpringBoot配置ActiveMQ
1.添加依赖 <!-- activeMQ --> <dependency> <groupId>org.springframework.boot</groupI ...
- springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息
1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...
- SpringBoot整合ActiveMQ,看这篇就够了
ActiveMQ是Apache提供的一个开源的消息系统,完全采用Java来实现,因此它能很好地支持JMS(Java Message Service,即Java消息服务)规范:本文将详细介绍下Activ ...
- SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...
- SpringBoot JMS(ActiveMQ) 使用实践
ActiveMQ 1. 下载windows办的activeMQ后,在以下目录可以启动: 2. 启动后会有以下提示 3. 所以我们可以通过http://localhost:8161访问管理页面,通过tc ...
- springboot与ActiveMQ整合
前言 很多项目, 都不是一个系统就做完了. 而是好多个系统, 相互协作来完成功能. 那, 系统与系统之间, 不可能完全独立吧? 如: 在学校所用的管理系统中, 有学生系统, 资产系统, 宿舍系统等等. ...
- SpringBoot集成ActiveMQ
前面提到了原生API访问ActiveMQ和Spring集成ActiveMQ.今天讲一下SpringBoot集成ActiveMQ.SpringBoot就是为了解决我们的Maven配置烦恼而生,因此使用S ...
随机推荐
- Spring Boot从入门到实战(十):异步处理
原文地址:http://blog.jboost.cn/2019/07/22/springboot-async.html 在业务开发中,有时候会遇到一些非核心的附加功能,比如短信或微信模板消息通知,或者 ...
- Python常用的标准库以及第三方库
Python常用的标准库以及第三方库有哪些? 20个必不可少的Python库也是基本的第三方库 读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们 ...
- HashMap源码__tableSizeFor方法解析
tableSizeFor(int cap)方法返回不小于指定参数cap的最小2的整数次幂,具体是怎么实现的呢?看源码! /** * Returns a power of two size for th ...
- Java学习笔记之---Servlet
Java学习笔记之---Servlet (一)如何实现Servlet 1.实现javax.servlet.Servlet接口: 2.继承javax.servlet.GenericServlet类: 3 ...
- Nodejs监控Apple召回计划&邮件提醒
最近,我的MacBook Pro 2015款13寸电池膨胀了 把笔记本平放在桌面,四个脚中的前两个无法落地,笔记本盖合上之后,屏幕上会印上键盘的纹路,也就是说,笔记本C面D面变形了,已经购买超过3年, ...
- 打包名命令:tar
将多个文件或目录包成一个大文件的命令功能,我们称它是一种"打包命令". tar的参数非常多,这里只列出几个常用的参数,更多的参数你可以自行man tar查询. [root@www ...
- mysql添加外键失败解决方案
mysql重启命令: [root@wshCentOS centOS7Share]# service mysqld stopRedirecting to /bin/systemctl stop mys ...
- python课堂整理17---文件操作(上)
1.在同一目录下新建文本文件 “爱了” 2.在该文件下写入内容,同时留意pycharm右下角的编码格式为 utf- 8 3.下面程序中的read函数会索引系统默认的编码格式,winx下是gbk ,所以 ...
- markdown表情
Emoji表情 将对应emoji表情的符号码复制后输入你的markdown文本即可显示emoji表情. 如:blush:,显示为
- [ PyQt入门教程 ] Qt Designer工具的使用
Qt Designer是PyQt程序UI界面的实现工具,Qt Designer工具使用简单,可以通过拖拽和点击完成复杂界面设计,并且设计完成的.ui程序可以转换成.py文件供python程序调用.本文 ...