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:代表作就是 ...
随机推荐
- fcntl设置FD_CLOEXEC标志作用【转】
本文转载自:https://blog.csdn.net/ustc_dylan/article/details/6930189 通过fcntl设置FD_CLOEXEC标志有什么用?close on ex ...
- git遇到error: RPC failed; curl 18 transfer closed with outstanding read data remaining fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed failed怎么办?
答: 将clone地址中的https://替换成git://即可解决 如: 将https://git.openwrt.org/project/luci.git修改为git://git.openwrt. ...
- snmp模拟器snmpsid使用
snmpsim使用 安装 pip install snmpsim 简单使用 生成snmpwalk文件: snmpwalk -v2c -c 'password' -ObentU 218.200.x.15 ...
- LOJ 2409「THUPC 2017」小 L 的计算题 / Sum
思路 和玩游戏一题类似 定义\(A_k(x)=\sum_{i=0}^\infty a_k^ix^i=\frac{1}{1-a_kx}\) 用\(\ln 'x\)代替\(\frac{1}{x}\), 所 ...
- UVA11107 Life Forms
思路 后缀数组 先都拼在一起 二分+height分段 按照小于x的为分界,判断是否有一个分段中包含超过n/2个串 代码 #include <cstdio> #include <cst ...
- Conclusions about Deep Learning with Python
Conclusions about Deep Learning with Python Last night, I start to learn the python for deep learn ...
- Git 与 GitHub 简介
Git 与 GitHub 的来历 Linux 之父 Linus 在 1991 年创建开源的 Linux 操作系统之后,多年来依靠全世界广大热心志愿者的共同建设,经过长足发展,现已成为世界上最大的服务器 ...
- Date中before和after方法的使用
Date1.after(Date2),当Date1大于Date2时,返回TRUE,当小于等于时,返回false: Date1.before(Date2),当Date1小于Date2时,返回TRUE,当 ...
- 使用jQuery修改带有!important 的强制样式
我们习惯性的会用这种方法进行修改: $(".test").css("width","100px !important"); 但是往往是修改失 ...
- 第二章 python变量及文件
1.环境变量 1.配置环境变量不是必须的2.配置环境变量的目的:为终端提供执行环境 2.Python代码执行 1.交互式 -- 控制台直接编写运行Python代码 -- 1.打 ...