1、配置连接信息

spring:
activemq:
broker-url: tcp://192.168.1.28:61616
user: admin
password: 123456
packages:
trust-all: true
jms:
pub-sub-domain: true

引入maven信息

<!-- 整合消息队列ActiveMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency> <!-- 如果配置线程池则加入 -->
<dependency>
<groupId>org.messaginghub</groupId>
<artifactId>pooled-jms</artifactId>
</dependency> <!--消息队列连接池-->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.15.0</version>
</dependency>

  

2、增加自定义配置

ActiveMqConfig.java
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import javax.jms.Queue;
import javax.jms.Topic; @Configuration
@EnableJms
public class ActiveMqConfig{ @Value("${queue}")
private String queueName; @Value("${topic}")
private String topicName; @Bean
public Queue queue(){
return new ActiveMQQueue(queueName);
} @Bean
public Topic topic(){
return new ActiveMQTopic(topicName);
}
}

  

生产者

ProducterService.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping; import javax.jms.Queue;
import javax.jms.Topic;
import java.util.List; /**
* 生产者
*/
@Component
public class ProducterService{ @Autowired
private JmsMessagingTemplate jmsMessagingTemplate; @Autowired
private Queue queue; @Autowired
private Topic topic; public void send1(String msg){
jmsMessagingTemplate.convertAndSend(queue, msg);
} public void sendQuene(Weixin object){
jmsMessagingTemplate.convertAndSend(queue, object);
} public void sendTopic(Weixin object){
jmsMessagingTemplate.convertAndSend(topic, object);
} }

  

消费者

ConsumerService.java
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component; import java.util.List; /**
* 消费者
*/
@Component
public class ConsumerService{ @JmsListener(destination = "${queue}")
public void receive12(String str) {
System.out.println(str);
System.out.println(11121);
} @JmsListener(destination = "${topic}")
public void receive2(Object object) {
System.out.println(object);
System.out.println(1112);
} @JmsListener(destination = "${topic}")
public void receive3(List list) {
System.out.println(list.size());
System.out.println(11144);
}
}

  

调用方式:

  /**
* 注入
*/
@Autowired
private ProducterService producterService; /**
* 调用
*/
producterService.sendQuene("11");

  

springboot 整合activemq的更多相关文章

  1. Web项目容器集成ActiveMQ & SpringBoot整合ActiveMQ

    集成tomcat就是随项目启动而启动tomcat,最简单的方法就是监听器监听容器创建之后以Broker的方式启动ActiveMQ. 1.web项目中Broker启动的方式进行集成 在这里采用Liste ...

  2. SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...

  3. SpringBoot整合ActiveMQ快速入门

    Spring Boot 具有如下特性: 为基于 Spring 的开发提供更快的入门体验 开箱即用,没有代码生成,也无需 XML 配置.同时也可以修改默认值来满足特定的需求. 提供了一些大型项目中常见的 ...

  4. 解决Springboot整合ActiveMQ发送和接收topic消息的问题

    环境搭建 1.创建maven项目(jar) 2.pom.xml添加依赖 <parent> <groupId>org.springframework.boot</group ...

  5. SpringBoot整合ActiveMQ和开启持久化

    一.点对点 1.提供者目录展示 2.导入依赖 <dependency> <groupId>org.springframework.boot</groupId> &l ...

  6. ActiveMQ 笔记(四)Spring\SpringBoot 整合 Activemq

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 一.Spring 整合Activemq 1.所需jar包 <dependencies> &l ...

  7. springboot整合ActiveMQ,配置问题

    1.ActiveMQ的安装和相关配置修改 去官网下载安装包解压至文件夹 双击打开 打开浏览器输入 http://127.0.0.1:8161 到此activeMQ就安装好了 2.springboot工 ...

  8. SpringBoot整合ActiveMQ,看这篇就够了

    ActiveMQ是Apache提供的一个开源的消息系统,完全采用Java来实现,因此它能很好地支持JMS(Java Message Service,即Java消息服务)规范:本文将详细介绍下Activ ...

  9. SpringBoot整合ActiveMQ发送邮件

    虽然ActiveMQ以被其他MQ所替代,但仍有学习的意义,本文采用邮件发送的例子展示ActiveMQ 1. 生产者1.1 引入maven依赖1.2 application.yml配置1.3 创建配置类 ...

  10. springboot整合activemq加入会签,自动重发机制,持久化

    消费者客户端成功接收一条消息的标志是:这条消息被签收. 消费者客户端成功接收一条消息一般包括三个阶段:          1.消费者接收消息,也即从MessageConsumer的receive方法返 ...

随机推荐

  1. 【 [SCOI2016]幸运数字】

    P3292 [SCOI2016]幸运数字 想法 倍增加上线性基就行惹 线性基的合并可以通过把一个线性基的元素插入到另一个里实现 #include<iostream> #include< ...

  2. LOJ 2555 & 洛谷 P4602 [CTSC2018]混合果汁(二分+主席树)

    LOJ 题目链接 & 洛谷题目链接 题意:商店里有 \(n\) 杯果汁,第 \(i\) 杯果汁有美味度 \(d_i\),单价为 \(p_i\) 元/升.最多可以添加 \(l_i\) 升.有 \ ...

  3. Atcoder Grand Contest 001 F - Wide Swap(拓扑排序)

    Atcoder 题面传送门 & 洛谷题面传送门 咦?鸽子 tzc 来补题解了?奇迹奇迹( 首先考虑什么样的排列可以得到.我们考虑 \(p\) 的逆排列 \(q\),那么每次操作的过程从逆排列的 ...

  4. Go语言核心36讲(Go语言实战与应用二十)--学习笔记

    42 | bufio包中的数据类型 (上) 今天,我们来讲另一个与 I/O 操作强相关的代码包bufio.bufio是"buffered I/O"的缩写.顾名思义,这个代码包中的程 ...

  5. FESTUNG模型介绍—1.对流方程求解

    FESTUNG模型介绍-1.对流方程求解 1. 控制方程 对流问题中,控制方程表达式为 \[\partial_t C + \partial_x (u^1 C) + \partial_y (u^2 C) ...

  6. MacBookpro安装VMware Fusion虚拟机,并安装win7 64位系统

    1.准备好安装用的东西(准备好正确的东西,安装路上就成功了一半)(1)VMware Fusion 附带注册机生成注册码,链接: https://pan.baidu.com/s/13Qm9zPOFjFt ...

  7. SPI详解2

    串行外设接口 (SPI) 总线是一种运行于全双工模式下的同步串行数据链路.用于在单个主节点和一个或多个从节点之间交换数据. SPI 总线实施简单,仅使用四条数据信号线和控制信号线(请参见图 1). 图 ...

  8. day01互联网架构理论

  9. InnoDB学习(二)之ChangeBuffer

    ChangeBuffer是InnoDB缓存区的一种特殊的数据结构,当用户执行SQL对非唯一索引进行更改时,如果索引对应的数据页不在缓存中时,InnoDB不会直接加载磁盘数据到缓存数据页中,而是缓存对这 ...

  10. JS控制元素的显示和隐藏

    利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位. 方法一: document.getElementB ...