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安全配置

【ActiveMQ】之安全机制(一)管控台安全设置

【ActiveMQ】之安全机制(二)客户端连接安全

【springboot】之整合ActiveMQ的更多相关文章

  1. springboot整合ActiveMQ,配置问题

    1.ActiveMQ的安装和相关配置修改 去官网下载安装包解压至文件夹 双击打开 打开浏览器输入 http://127.0.0.1:8161 到此activeMQ就安装好了 2.springboot工 ...

  2. SpringBoot2.0源码分析(二):整合ActiveMQ分析

    SpringBoot具体整合ActiveMQ可参考:SpringBoot2.0应用(二):SpringBoot2.0整合ActiveMQ ActiveMQ自动注入 当项目中存在javax.jms.Me ...

  3. Web项目容器集成ActiveMQ & SpringBoot整合ActiveMQ

    集成tomcat就是随项目启动而启动tomcat,最简单的方法就是监听器监听容器创建之后以Broker的方式启动ActiveMQ. 1.web项目中Broker启动的方式进行集成 在这里采用Liste ...

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

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

  5. SpringBoot整合ActiveMQ快速入门

    Spring Boot 具有如下特性: 为基于 Spring 的开发提供更快的入门体验 开箱即用,没有代码生成,也无需 XML 配置.同时也可以修改默认值来满足特定的需求. 提供了一些大型项目中常见的 ...

  6. SpringBoot 2.x (13):整合ActiveMQ

    ActiveMQ5.x不多做介绍了,主要是SpringBoot的整合 特点: 1)支持来自Java,C,C ++,C#,Ruby,Perl,Python,PHP的各种跨语言客户端和协议 2)支持许多高 ...

  7. SpringBoot第二十一篇:整合ActiveMQ

    作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/11190048.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言   前一章节中 ...

  8. 解决Springboot整合ActiveMQ发送和接收topic消息的问题

    环境搭建 1.创建maven项目(jar) 2.pom.xml添加依赖 <parent> <groupId>org.springframework.boot</group ...

  9. SpringBoot整合ActiveMQ和开启持久化

    一.点对点 1.提供者目录展示 2.导入依赖 <dependency> <groupId>org.springframework.boot</groupId> &l ...

随机推荐

  1. Git版本退回和修改

    首先我们来看看我们的第一个版本: 我的git文件如下: 那我们来修改一下这个文件 然后提交 那我们来查看一下提交的记录:使用git log 当我们使用 git log --pretty=oneline ...

  2. tflearn weights获取与存储

    参考: http://tflearn.org/examples/

  3. [LeetCode&Python] Problem 824. Goat Latin

    A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...

  4. 论Injection的前世今生

    Click me~ why Java EE provides injection mechanisms that enable your objects to obtain references to ...

  5. Electron 快速入门

    https://www.w3cschool.cn/electronmanual/p9al1qkx.html

  6. C++学习(五)(C语言部分)之 运算符

    运算符学习时的笔记(其实也没什么用,留着给自己看的) 运算符 用来对数据运算的符号 优先级 3+4*5+6 先乘除 然后加减 运算符优先级高就先算 40多个运算符 15层优先级 不需要背 1.查表 2 ...

  7. 求连续数字的和------------------------------用while的算法思想

    前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.as ...

  8. c的动态内存管理

    在linux系统下使用malloc提示警告,解决方法,加入头文件<stdlib.h> 首先来个基本的例子 int *p=(int *)malloc(sizeof(int));(当mallo ...

  9. WikiBooks/Cg Programming

    https://en.wikibooks.org/wiki/Cg_Programming Basics Minimal Shader(about shaders, materials, and gam ...

  10. Unity 资源的优化管理 学习