1 Spring Boot与ActiveMQ整合

1.1使用内嵌服务

(1)在pom.xml中引入ActiveMQ起步依赖

<properties>
<spring.version>2.0.7.RELEASE</spring.version>
</properties> <dependencies>
<!--springmvc-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!--activemq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
<!--spirngboot热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>

(2)创建消息生产者(application 引导类 必须 和要访问的类 在同一级包下) QueueController.java

@RestController
@RequestMapping("/queue")
public class QueueController { @Autowired
private JmsMessagingTemplate jmsMessagingTemplate; @RequestMapping("/send")
public void send(String text){
jmsMessagingTemplate.convertAndSend("code",text);
} }

(3)创建消息消费者 QueueConsumer

@Component
public class QueueConsumer { @JmsListener(destination = "code")
public void readMessage(String text){
System.out.println("接收到的消息 : " + text);
} }

测试:启动服务后,在浏览器执行

http://localhost:8088/send.do?text=aaaaa

即可看到控制台输出消息提示。Spring Boot内置了ActiveMQ的服务,所以我们不用单独启动也可以执行应用程序。

1.2使用外部服务

在src/main/resources下的application.properties增加配置, 指定ActiveMQ的地址

spring.activemq.broker-url=tcp://192.168.25.130:61616

application.properties配置

# tomcat服务器端口号
server.port=8080
url=http://www.baidu.com
# activemq地址
spring.activemq.broker-url=tcp://192.168.200.128:61616

运行后,会在activeMQ中看到发送的queue

1.3发送Map信息

(1)向QueueController.java添加代码

@RequestMapping("/sendmap")
public void sendMap(){
Map map = new HashMap();
map.put("name", "曜");
map.put("sex", "男");
map.put("age", "18");
jmsMessagingTemplate.convertAndSend("codemap",map);
}

(2)向Consumer.java添加代码

 @JmsListener(destination = "codemap")
public void readMap(Map map){
System.out.println(map);
}

http://localhost:8088/sendmap

控制台打印

spring boot 整合activemq的更多相关文章

  1. spring boot整合activemq消息中间件

    spring boot整合activemq消息中间件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi ...

  2. activeMQ入门+spring boot整合activeMQ

    最近想要学习MOM(消息中间件:Message Oriented Middleware),就从比较基础的activeMQ学起,rabbitMQ.zeroMQ.rocketMQ.Kafka等后续再去学习 ...

  3. Spring Boot 整合 ActiveMQ

    依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spri ...

  4. Spring Boot入门 and Spring Boot与ActiveMQ整合

    1.Spring Boot入门 1.1什么是Spring Boot Spring 诞生时是 Java 企业版(Java Enterprise Edition,JEE,也称 J2EE)的轻量级代替品.无 ...

  5. Spring Boot与ActiveMQ整合

    Spring Boot与ActiveMQ整合 1使用内嵌服务 (1)在pom.xml中引入ActiveMQ起步依赖 <dependency> <groupId>org.spri ...

  6. RabbitMQ使用及与spring boot整合

    1.MQ 消息队列(Message Queue,简称MQ)——应用程序和应用程序之间的通信方法 应用:不同进程Process/线程Thread之间通信 比较流行的中间件: ActiveMQ Rabbi ...

  7. Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询

    摘要: 原创出处 www.bysocket.com 「泥瓦匠BYSocket 」欢迎转载,保留摘要,谢谢! 『 预见未来最好的方式就是亲手创造未来 – <史蒂夫·乔布斯传> 』 运行环境: ...

  8. spring boot整合jsp的那些坑(spring boot 学习笔记之三)

    Spring Boot 整合 Jsp 步骤: 1.新建一个spring boot项目 2.修改pom文件 <dependency>            <groupId>or ...

  9. spring boot 系列之四:spring boot 整合JPA

    上一篇我们讲了spring boot 整合JdbcTemplate来进行数据的持久化, 这篇我们来说下怎么通过spring boot 整合JPA来实现数据的持久化. 一.代码实现 修改pom,引入依赖 ...

随机推荐

  1. CodeForces-437C(贪心)

    链接: https://vjudge.net/problem/CodeForces-437C 题意: On Children's Day, the child got a toy from Delay ...

  2. pyqt5-QTDesigner--控件操作

    Edit菜单       编辑小伙伴.用鼠标直接拖       编辑控件---样式等等. 点击需要编辑的控件--->   信号与槽 先用鼠标从控件往外拖---> --->选中相应的信 ...

  3. C++在delete指针后要赋值为NULL

    C++标准规定:delete空指针是合法的,没有副作用. 所以我们在Delete指针后赋值为NULL或0是个好习惯.对一个非空指针delete后,若没有赋NULL,若再次delete的话 有可能出现问 ...

  4. C#Regex中replace方法的替换自定义小数点后的内容

    $1应该就是引用了这个组,不用这个会匹配不到 /// <summary> /// 截取 /// </summary> /// <param name="n&qu ...

  5. 微信小程序访问后台出现 对应的服务器证书无效。控制台输入 showRequestInfo() 可以获取更详细信息。

    检查微信开发者平台配置 https 服务端 nginx 配置 ssl 协议是否有效 在开发者工具中可以使用(详情 > 不校验合法域名.web-view(业务域名).TLS 版本以及 HTTPS ...

  6. Bug管理工具MantisBT-2.18.0安装教程

    Bug管理工具MantisBT安装教程 MantisBT官网下载地址:https://sourceforge.net/projects/mantisbt/# 写于:2018.12.1 如上传博客资料图 ...

  7. [LeetCode]-DataBase-Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  8. Spring MVC过滤器HiddenHttpMethodFilter

    浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...

  9. linux fedora原生的快捷键操作

    显示桌面: ctrl+alt+d 运行终端程序: gnome-terminal : 可以自定义快捷键: ctrl+T 等等.

  10. ERROR:imshow、Mat、waitkey找不到标识符(opencv)

    可以发现imshow.Mat.waitkey这三个都是opencv相关的. 在添加了相关库文件后还是有问题. #include "stdafx.h" #include <st ...