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. Jenkins-slave分布式环境构建与并行WebUi自动化测试项目

    前言 之前搭建过selenium grid的分布式环境,今天我们再来搭建一次Jenkins的分布式环境:jenkins-slave Jenkins的Master-Slave分布式架构主要是为了解决Je ...

  2. 基于ReentrantLock的非公平锁理解AQS

    AQS AQS概述 ​ AbstractQueuedSynchronizer抽象队列同步器简称AQS,它是实现同步器的基础组件,juc下面Lock的实现以及一些并发工具类就是通过AQS来实现的,这里我 ...

  3. Linux平台 Oracle 19c RAC安装Part2:GI配置

    三.GI(Grid Infrastructure)安装 3.1 解压GI的安装包 3.2 安装配置Xmanager软件 3.3 共享存储LUN的赋权 3.4 使用Xmanager图形化界面配置GI 3 ...

  4. 【Java】Map

    今天用到了键-值对,于是想起了 Java 的 Map,由于之前并不很熟悉,就看了下源码,如下: /* * Copyright (c) 1997, 2006, Oracle and/or its aff ...

  5. 使用用树莓派打造远程WEB服务器

    简介:系统配置Raspberry Pi 3B + Raspbian + MySQL5.7 + Tomcat 9 + Nginx + 公网IP. 工具:Win32DiskImager .FileZill ...

  6. 深入理解JVM-java字节码文件结构剖析(1)

    public class MyTest1 { private int a = 1; public int getA() { return a; } public void setA(int a) { ...

  7. plotly之set_credentials_file问题

    相信了解可视化的同学们都听说过plotly,笔者也是第一次了解这个网站,然后兴冲冲地设置,但是没想到第一次进行在线账号初始化就出现了问题! python3报错为module 'plotly.tools ...

  8. CEPH 自动化测试用例介绍

    1.QA 的内部逻辑关系. 首先用一个图表示一下QA的内部的逻辑关系. 2.QA的脚本介绍 3.QA脚本运行

  9. kylin Retrieving hive dependency...

    由于公司环境配置hive默认连接hiveserver2 ,不管hive cli 还是beeline cli都默认使用beeline cli,连接hive需要输入账号密码; 启动kylin 时会Retr ...

  10. ThreadLocal线程隔离

    package com.cookie.test; import java.util.concurrent.atomic.AtomicInteger; /** * author : cxq * Date ...