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. Gym - 101981M:(南京) Mediocre String Problem(回文树+exkmp)

    #include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(int i=a;i<=b;i++) using ...

  2. hdu4135 Co-prime 容斥原理

    Given a number N, you are asked to count the number of integers between A and B inclusive which are ...

  3. ionic1实现热更新以版本检测更新安装包的方法

    1.需要下载热更新插件:插件名称是cordova-hot-code-push 首先打开cli,执行命令 npm install -g cordova-hot-code-push-cli 此功能主要是为 ...

  4. [工作记录] NDK: AKEYCODE_DEL not notified

    https://code.google.com/p/android/issues/detail?id=42904#makechanges 我们游戏的输入系统是自己渲染(通过跨平台渲染接口)的. 首先有 ...

  5. @PropertySouce注解

    1.@ProtertySource @PropertySouce是spring3.1开始引入的基于java config的注解. 通过@PropertySource注解将properties配置文件中 ...

  6. 取消svn关联文件夹

    svn没有自带取消svn关联功能,所以我们需要以下脚本 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classe ...

  7. RESTful Web API 理解

    REST 是一种应用架构风格,不是一种标准,是面向资源架构(ROA)风格,与具体技术平台无关,REST架构的应用未必建立在Web之上,与之对应的是传统的Web Service 采用的面向操作的RPC架 ...

  8. HTTP请求属性说明

    1)URL:页面地址. 2)Method :页面的提交方式,POST或GET. 3)EncType:编码类型.此参数给出一个内容类型(Content-Type),指定其做为回放脚本时“Content- ...

  9. Revit api 创建楼梯图元

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. gaea-editor 知识点

    github 地址:https://github.com/ascoders/gaea-editor