SpringBoot配置ActiveMQ
1、添加依赖
<!-- activeMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<!-- activeMQ的连接池 -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
2、application.properties配置
spring.activemq.broker-url=tcp://localhost:61616
spring.activemq.user=admin
spring.activemq.password=admin
#queue和topic不能同时使用(我不会同时使用),使用topic的时候,把下面这行解除注释
#spring.jms.pub-sub-domain=true
spring.activemq.pool.enabled=false
spring.activemq.pool.max-connections=
3、生产者
import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.Topic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class ProducerController { @Autowired
private JmsMessagingTemplate jmsMessagingTemplate; @Autowired
private Queue queue; @Autowired
private Topic topic; /*
* 消息生产者
*/
@RequestMapping("/sendQueueMsg")
public void sendQueueMsg(String msg) {
this.jmsMessagingTemplate.convertAndSend(this.queue, msg);
} @RequestMapping("/sendTopicMsg")
public void sendTopicMsg(String msg) {
// 指定消息发送的目的地及内容
System.out.println("@@@@@@@@@@@@@@" + msg);
this.jmsMessagingTemplate.convertAndSend(this.topic, msg);
}
}
4、消费者
import org.springframework.jms.annotation.JmsListener;
import org.springframework.web.bind.annotation.RestController; @RestController
public class ConsumerController { /**
* 监听和读取queue消息
* @param message
*/
@JmsListener(destination="active.queue")
public void readActiveQueue(String message) {
System.out.println("接受到:" + message);
//TODO something
} /**
* 监听和读取topic消息
* @param message
*/
@JmsListener(destination="active.topic")
public void readActiveTopic(String message) {
System.out.println("接受到:" + message);
//TODO something
}
}
5、发布/订阅的主题名称
import javax.jms.Queue;
import javax.jms.Topic; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms; @Configuration
@EnableJms
public class JmsConfig { private static final String QUEUE_NAME = "active.queue"; private static final String TOPIC_NAME = "active.topic"; @Bean
public Queue queue(){
return new ActiveMQQueue(QUEUE_NAME);
} @Bean
public Topic topic(){
return new ActiveMQTopic(TOPIC_NAME);
}
}
测试
浏览器输入:
http://localhost:8080/sendQueueMsg?msg=dddddd

SpringBoot配置ActiveMQ的更多相关文章
- springBoot配置activeMq点对点模式消费信息以及独占模式消费如何设置
1.在pom文件中引入对应jar包 <!--activeMQ start--> <dependency> <groupId>org.springframework. ...
- SpringBoot配置activemq消息队列
1.配置pom相关依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...
- SpringBoot JMS(ActiveMQ) 使用实践
ActiveMQ 1. 下载windows办的activeMQ后,在以下目录可以启动: 2. 启动后会有以下提示 3. 所以我们可以通过http://localhost:8161访问管理页面,通过tc ...
- Web项目容器集成ActiveMQ & SpringBoot整合ActiveMQ
集成tomcat就是随项目启动而启动tomcat,最简单的方法就是监听器监听容器创建之后以Broker的方式启动ActiveMQ. 1.web项目中Broker启动的方式进行集成 在这里采用Liste ...
- springboot与ActiveMQ整合
前言 很多项目, 都不是一个系统就做完了. 而是好多个系统, 相互协作来完成功能. 那, 系统与系统之间, 不可能完全独立吧? 如: 在学校所用的管理系统中, 有学生系统, 资产系统, 宿舍系统等等. ...
- SpringBoot配置(1) 配置文件application&yml
SpringBoot配置(1) 配置文件application&yml 一.配置文件 1.1 配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的. application ...
- SpringBoot集成ActiveMQ
前面提到了原生API访问ActiveMQ和Spring集成ActiveMQ.今天讲一下SpringBoot集成ActiveMQ.SpringBoot就是为了解决我们的Maven配置烦恼而生,因此使用S ...
- SpringBoot配置属性之MQ
SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...
- SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...
随机推荐
- HBase API 基础操作
对于数据操作,HBase支持四类主要的数据操作,分别是: Put :增加一行,修改一行 Delete :删除一行,删除指定列族,删除指定column的多个版本,删除指定column的制定版本等 Get ...
- 开发过程中 的一些 补充知识点 + 关于mysql中的日期和时间函数?
参考: https://www.jb51.net/article/23966.htm https://yq.aliyun.com/articles/260389 mysql中的 日期格式是: HHHH ...
- IT项目管理十大要素
1.项目需求PgMp.mypm.net 当项目混乱和不可控的时候,往往是源头出了问题,解决源头才能治本.项目管理者联盟文章 软件项目中的范围管理重点就是项目需求,需求包括原始需求,用户需求,产品需求和 ...
- threejs深入纹理,立体场景cubeResolution(四)
在这个课程里主要完成讲解两个demo: 一个是电视墙:用视频做纹理 一,用视频做纹理 首先我们用video标签把视频源引入: <video id="video" autopl ...
- MySQL自定义函数递归查询
用于递归查找Id(通过parentId关联)参数为int 类型的值: CREATE DEFINER=`root`@`%` FUNCTION `getChildList`(rootId INT) RET ...
- B/S架构
B/S架构即浏览器和服务器架构模式.它是随着Internet技术的兴起,对C/S架构的一种变化或者改进的架构.在这种架构下,用户工作界面是通过WWW浏览器来实现,极少部分事务逻辑在前端(Browser ...
- 在阿里云开源镜像站中下载centOS7
镜像的选择 第一步.下载镜像 阿里云开源镜像站:http://mirrors.aliyun.com/ 选择centos进入 如下图: 如下图:选择centos7 再选择isos(镜像目录) 继续下一步 ...
- vue使用webapck的最基本最简单的开发环境配置
这个配置生成出来的代码只能支持ES6的浏览器下正常显示. npm init -y npm install vue-loader vue-template-compiler vue-style-load ...
- 论文笔记(Filter Pruning via Geometric Median for Deep Convolutional Neural Networks Acceleration)
这是CVPR 2019的一篇oral. 预备知识点:Geometric median 几何中位数 \begin{equation}\underset{y \in \mathbb{R}^{n}}{\ar ...
- php(三)使用thinkphp操作数据库
1.数据库设置 在项目D:\workspaces\phpDemo01\helloworldProject\Common\Conf\config.php配置: <?php return array ...