spring boot 整合activemq
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);
}
控制台打印

spring boot 整合activemq的更多相关文章
- spring boot整合activemq消息中间件
spring boot整合activemq消息中间件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi ...
- activeMQ入门+spring boot整合activeMQ
最近想要学习MOM(消息中间件:Message Oriented Middleware),就从比较基础的activeMQ学起,rabbitMQ.zeroMQ.rocketMQ.Kafka等后续再去学习 ...
- Spring Boot 整合 ActiveMQ
依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spri ...
- Spring Boot入门 and Spring Boot与ActiveMQ整合
1.Spring Boot入门 1.1什么是Spring Boot Spring 诞生时是 Java 企业版(Java Enterprise Edition,JEE,也称 J2EE)的轻量级代替品.无 ...
- Spring Boot与ActiveMQ整合
Spring Boot与ActiveMQ整合 1使用内嵌服务 (1)在pom.xml中引入ActiveMQ起步依赖 <dependency> <groupId>org.spri ...
- RabbitMQ使用及与spring boot整合
1.MQ 消息队列(Message Queue,简称MQ)——应用程序和应用程序之间的通信方法 应用:不同进程Process/线程Thread之间通信 比较流行的中间件: ActiveMQ Rabbi ...
- Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询
摘要: 原创出处 www.bysocket.com 「泥瓦匠BYSocket 」欢迎转载,保留摘要,谢谢! 『 预见未来最好的方式就是亲手创造未来 – <史蒂夫·乔布斯传> 』 运行环境: ...
- spring boot整合jsp的那些坑(spring boot 学习笔记之三)
Spring Boot 整合 Jsp 步骤: 1.新建一个spring boot项目 2.修改pom文件 <dependency> <groupId>or ...
- spring boot 系列之四:spring boot 整合JPA
上一篇我们讲了spring boot 整合JdbcTemplate来进行数据的持久化, 这篇我们来说下怎么通过spring boot 整合JPA来实现数据的持久化. 一.代码实现 修改pom,引入依赖 ...
随机推荐
- haproxy教程
一.haproxy简介 HAProxy is a free, very fast and reliable solution offering high availability, load bala ...
- 【NOIP2016提高A组模拟9.24】我的快乐时代
题目 分析 虽然我们很难求出\(\sum_{i=n}^mjoy(i)\), 但是我们可以分别求出\(\sum_{i=1}^mjoy(i)\)和\(\sum_{i=1}^{n-1}joy(i)\),相减 ...
- 【leetcode】Sliding Puzzle
题目如下: On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square ...
- Vue结合后台的增删改案例
首先列表内容还是与之前的列表内容类似,不过此处我们会采用Vue中数据请求的方式来实现数据的增删.那么我们使用的Vue第三方组件就是vue-resource,vue发起请求的方式与jQuery的ajax ...
- DevOps之持续集成Jenkins+Gitlab
一.什么是DevOps DevOps(英文Development(开发)和Operations(技术运营)的组合)是一组过程.方法与系统的统称,DevOps是一组最佳实践强调(开发.运维.测试)在应用 ...
- 学习经常遇到的浮动(float)
参考自 小辉随笔: https://www.cnblogs.com/lchsirblog/p/9582989.html 一.什么时候需要使用浮动 最常见的情景是:多个块级元素(如div)需要同一行显示 ...
- 电脑右键新建没有xmind文件选项解决方法
xmind还是方便的. 打开注册表,展开HKEY_CLASSES_ROOT,展开.xmind(如果没有请新建).在里面新建ShellNew项,并展开,在里面新建NullFile这个字符串值. 如果还是 ...
- ASP.NET如何实现断点续传的上传、下载功能?
1 背景 用户本地有一份txt或者csv文件,无论是从业务数据库导出.还是其他途径获取,当需要使用蚂蚁的大数据分析工具进行数据加工.挖掘和共创应用的时候,首先要将本地文件上传至ODPS,普通的小文件通 ...
- Mybatis学习笔记之---多表查询(2)
Mybatis多表查询(2) (一)举例 用户和角色 一个用户可以有多个角色,一个角色可以赋予多个用户 (二)步骤 1.建立两张表:用户表,角色表,让用户表和角色表具有多对多的关系.需要使用中间表,中 ...
- python学习之路(22)
使用模块 Python本身就内置了很多非常有用的模块,只要安装完毕,这些模块就可以立刻使用. 我们以内建的sys模块为例,编写一个hello的模块: #!/usr/bin/env python # - ...