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点对点模式消费信息以及独占模式消费如何设置的更多相关文章

  1. SpringBoot整合ActiveMq实现Queue和Topic两种模式(看不懂你来打我)

    目录 一.前言 二.ActiveMq的下载和使用 三.依赖准备 四.yml文件配置 五.配置Bean 六.创建生产者(Queue+Topic) 七.创建消费者(Topic模式下) 八.测试结果(Top ...

  2. SpringBoot配置activemq消息队列

    1.配置pom相关依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  3. SpringBoot配置ActiveMQ

    1.添加依赖 <!-- activeMQ --> <dependency> <groupId>org.springframework.boot</groupI ...

  4. springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息

    1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...

  5. SpringBoot整合ActiveMQ,看这篇就够了

    ActiveMQ是Apache提供的一个开源的消息系统,完全采用Java来实现,因此它能很好地支持JMS(Java Message Service,即Java消息服务)规范:本文将详细介绍下Activ ...

  6. SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...

  7. SpringBoot JMS(ActiveMQ) 使用实践

    ActiveMQ 1. 下载windows办的activeMQ后,在以下目录可以启动: 2. 启动后会有以下提示 3. 所以我们可以通过http://localhost:8161访问管理页面,通过tc ...

  8. springboot与ActiveMQ整合

    前言 很多项目, 都不是一个系统就做完了. 而是好多个系统, 相互协作来完成功能. 那, 系统与系统之间, 不可能完全独立吧? 如: 在学校所用的管理系统中, 有学生系统, 资产系统, 宿舍系统等等. ...

  9. SpringBoot集成ActiveMQ

    前面提到了原生API访问ActiveMQ和Spring集成ActiveMQ.今天讲一下SpringBoot集成ActiveMQ.SpringBoot就是为了解决我们的Maven配置烦恼而生,因此使用S ...

随机推荐

  1. 使用 Spring Framework 时常犯的十大错误

    Spring 可以说是最流行的 Java 框架之一,也是一只需要驯服的强大野兽.虽然它的基本概念相当容易掌握,但成为一名强大的 Spring 开发者仍需要很多时间和努力. 在本文中,我们将介绍 Spr ...

  2. 2015.11.27---Java

    public class star{ public static void main(String[] args) { System.out.print("ha"); } }

  3. MVC WebApi 实现Token验证

    基于令牌的认证 我们知道WEB网站的身份验证一般通过session或者cookie完成的,登录成功后客户端发送的任何请求都带上cookie,服务端根据客户端发送来的cookie来识别用户. WEB A ...

  4. helm安装MINIO文件服务器

    MinIO Quickstart Guide MinIO 是一个基于Apache License v2.0开源协议的对象存储服务.它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例 ...

  5. Linux基础之快照克隆、Xshell优化、Linux历史

    今天主要分享4个Linux基础知识,第一个知识是虚拟机快照,第二个是虚拟机克隆,第三个是优化Xshell,第四个是简述Linux历史. 先分享第一个知识——虚拟机快照. 1.4)虚拟机快照 虚拟机快照 ...

  6. 序列化Serializable接口

    一.序列化 1.什么是序列化? 序列化就是将对象的状态存储到特定存储介质中的过程,也就是将对象状态转换为可保持或传输格式的过程. 在序列化过程中,会将对象的公有成员.私有成员(包括类名),转换为字节流 ...

  7. java 第五章

    java 第五章   while 循环语句 语法:while(循环条件){ //循环操作 循环条件自加: } while循环结构的特点:先判断,在执行.    while   的执行步骤 (1) 声明 ...

  8. 基于 Autojs 的 APP、小程序自动化测试 SDK

    原文:https://blog.csdn.net/laobingm/article/details/98317394 autojs sdk基于 Autojs 的 APP.小程序自动化测试 SDK,支持 ...

  9. JAVA并发编程之倒计数器CountDownLatch

    CountDownLatch 的使用场景:在主线程中开启多线程去并行执行任务,并且主线程需要等待所有子线程执行完毕后汇总返回结果. 我把源码中的英文注释全部删除,写上自己的注释.就剩下 70 行不到的 ...

  10. div 环形排列

    javascript-按圆形排列DIV元素(一)---- 分析 效果图: 一.分析图: 绿色边框内:外层的DIV元素,相对定位; 白色圆形框:辅助分析的想象形状; 白点:为白色圆形的圆心点,中心点,点 ...