ActiveMQ(06):ActiveMQ结合Spring开发

简介:

一、pom.xml与mq.properties

Spring提供了对JMS的支持,需要添加Spring支持jms的包,如下:

1
2
3
4
5
< dependency >
     < groupId >org.springframework</ groupId >
     < artifactId >spring-jms</ artifactId >
     < version >4.1.7.RELEASE</ version >
</ dependency >

添加ActiveMQ的pool包,如下:

1
2
3
4
5
< dependency >
     < groupId >org.apache.activemq</ groupId >
     < artifactId >activemq-pool</ artifactId >
     < version >5.11.1</ version >
</ dependency >

添加xbean的标签配置,如下:

1
2
3
4
5
< dependency >
     < groupId >org.apache.xbean</ groupId >
     < artifactId >xbean-spring</ artifactId >
     < version >3.16</ version >
</ dependency >

pom.xml完整配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
< properties >
     < activemq.version >5.9.0</ activemq.version >
     < activemq-pool.version >5.11.1</ activemq-pool.version >
     < spring.version >4.1.7.RELEASE</ spring.version >
     < xbean.version >3.16</ xbean.version >
     < commons-lang3.version >3.3.2</ commons-lang3.version >
     < commons-io.version >2.4</ commons-io.version >
     < commons-fileupload.version >1.3.1</ commons-fileupload.version >
     < fasterxml.jackson.version >2.8.4</ fasterxml.jackson.version >
     < codehaus.jackson.version >1.9.13</ codehaus.jackson.version >
</ properties >
< dependencies >
     < dependency >
         < groupId >junit</ groupId >
         < artifactId >junit</ artifactId >
     < version >${junit.version}</ version >
     </ dependency >
     <!-- Apache工具组件 -->
     < dependency >
         < groupId >org.apache.commons</ groupId >
         < artifactId >commons-lang3</ artifactId >
     < version >${commons-lang3.version}</ version >
     </ dependency >
     < dependency >
         < groupId >commons-io</ groupId >
         < artifactId >commons-io</ artifactId >
     < version >${commons-io.version}</ version >
     </ dependency >
     < dependency >
         < groupId >commons-fileupload</ groupId >
     < artifactId >commons-fileupload</ artifactId >
     < version >${commons-fileupload.version}</ version >
     </ dependency >
     <!-- jackson -->
     < dependency >
         < groupId >com.fasterxml.jackson.core</ groupId >
     < artifactId >jackson-databind</ artifactId >
     < version >${fasterxml.jackson.version}</ version >
     </ dependency >
     < dependency >
         < groupId >com.fasterxml.jackson.core</ groupId >
     < artifactId >jackson-core</ artifactId >
     < version >${fasterxml.jackson.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.codehaus.jackson</ groupId >
     < artifactId >jackson-core-asl</ artifactId >
         < version >${codehaus.jackson.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.codehaus.jackson</ groupId >
     < artifactId >jackson-mapper-asl</ artifactId >
     < version >${codehaus.jackson.version}</ version >
     </ dependency >
     <!-- activemq -->
     < dependency >
         < groupId >org.apache.activemq</ groupId >
     < artifactId >activemq-all</ artifactId >
     < version >${activemq.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.apache.activemq</ groupId >
     < artifactId >activemq-pool</ artifactId >
     < version >${activemq-pool.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.springframework</ groupId >
     < artifactId >spring-jms</ artifactId >
     < version >${spring.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.apache.xbean</ groupId >
     < artifactId >xbean-spring</ artifactId >
     < version >${xbean.version}</ version >
     </ dependency >
     <!-- spring -->
     < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-context</ artifactId >
     < version >${spring.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.springframework</ groupId >
     < artifactId >spring-context-support</ artifactId >
     < version >${spring.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.springframework</ groupId >
     < artifactId >spring-beans</ artifactId >
     < version >${spring.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.springframework</ groupId >
     < artifactId >spring-webmvc</ artifactId >
     < version >${spring.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-jdbc</ artifactId >
     < version >${spring.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.springframework</ groupId >
     < artifactId >spring-aspects</ artifactId >
     < version >${spring.version}</ version >
     </ dependency >
     < dependency >
         < groupId >org.springframework</ groupId >
     < artifactId >spring-test</ artifactId >
     < version >${spring.version}</ version >
     </ dependency >
</ dependencies >

二、mq.xml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<? xml  version = "1.0"  encoding = "UTF-8" ?>
< beans  xmlns = "http://www.springframework.org/schema/beans"
     xmlns:context = "http://www.springframework.org/schema/context"
     xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:amq = "http://activemq.apache.org/schema/core"
     xmlns:jms = "http://www.springframework.org/schema/jms"
     xsi:schemaLocation="http://www.springframework.org/schema/beans   
         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd   
         http://www.springframework.org/schema/context   
         http://www.springframework.org/schema/context/spring-context-4.0.xsd
         http://www.springframework.org/schema/jms
         http://www.springframework.org/schema/jms/spring-jms-4.0.xsd
         http://activemq.apache.org/schema/core
         http://activemq.apache.org/schema/core/activemq-core-5.8.0.xsd">
     
     <!-- ActiveMQ 连接工厂 -->
     <!-- 真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供-->
     <!-- 如果连接网络:tcp://ip:61616;未连接网络:tcp://localhost:61616 以及用户名,密码-->
     < amq:connectionFactory  id = "amqConnectionFactory"  brokerURL = "${activemq.brokerURL}"  userName = "${activemq.userName}"  password = "${activemq.password}"  />
     
     <!-- Spring Caching连接工厂 -->
     <!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory -->  
     < bean  id = "connectionFactory"  class = "org.springframework.jms.connection.CachingConnectionFactory" >
         <!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory -->  
         < property  name = "targetConnectionFactory"  ref = "amqConnectionFactory" ></ property >
         <!-- 同上,同理 -->
         <!-- <constructor-arg ref="amqConnectionFactory" /> -->
         <!-- Session缓存数量 -->
         < property  name = "sessionCacheSize"  value = "100"  />
         <!-- 接收者ID,用于Topic订阅者的永久订阅-->
                 < property  name = "clientId"  value = "client-C"  /> 
     </ bean >
     
     <!-- =======Spring JmsTemplate 的消息生产者【开始】======== -->
     <!-- 定义JmsTemplate的Queue类型 -->
     < bean  id = "jmsQueueTemplate"  class = "org.springframework.jms.core.JmsTemplate" >
         <!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 -->  
         < constructor-arg  ref = "connectionFactory"  />
         <!-- 非pub/sub模型(发布/订阅),即队列模式 -->
         < property  name = "pubSubDomain"  value = "false"  />
     </ bean >
 
     <!-- 定义JmsTemplate的Topic类型 -->
     < bean  id = "jmsTopicTemplate"  class = "org.springframework.jms.core.JmsTemplate" >
          <!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 -->  
         < constructor-arg  ref = "connectionFactory"  />
         <!-- pub/sub模型(发布/订阅) -->
         < property  name = "pubSubDomain"  value = "true"  />
     </ bean >
     <!-- =======Spring JmsTemplate 的消息生产者【结束】======== -->
     
     <!-- =======消息消费者=======【开始】 -->
     <!-- 定义Queue监听器 -->
     < jms:listener-container  destination-type = "queue"  container-type = "default"  connection-factory = "connectionFactory"  acknowledge = "auto" >
         < jms:listener  destination = "test.queue"  ref = "queueReceiver1" />
         < jms:listener  destination = "test.queue"  ref = "queueReceiver2" />
     </ jms:listener-container >
 
     <!-- 定义Topic监听器 -->
     <!-- 非持久化 -->
     < jms:listener-container  destination-type = "topic"  container-type = "default"  connection-factory = "connectionFactory"  acknowledge = "auto" >
         < jms:listener  destination = "test.topic"  ref = "topicReceiver1" />
     </ jms:listener-container >
     <!-- 持久化 -->
         < jms:listener-container  destination-type = "durableTopic"  container-type = "default"  connection-factory = "connectionFactory"  acknowledge = "auto"  client-id = "client-C" >
             < jms:listener  destination = "test.topic2"  subscription = "topicReceiver2"  ref = "topicReceiver2" />
         </ jms:listener-container >
     <!-- =======消息消费者=======【结束】 -->
</ beans >

三、java类

3.1 消费者监听器

3.1.1 队列消息监听器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package  com.liuy.mq.consumer.queue;
 
import  javax.jms.JMSException;
import  javax.jms.Message;
import  javax.jms.MessageListener;
import  javax.jms.TextMessage;
 
import  org.springframework.stereotype.Component;
 
/**
  * 队列消息监听器1
  * @description 队列消息监听器1
  * @author liuy
  * @version V1.00
  * @date:2017年4月12日上午10:15:19
  */
@Component
public  class  QueueReceiver1  implements  MessageListener {
 
     @Override
     public  void  onMessage(Message message) {
         try  {
         System.out.println( "QueueReceiver1接收到消息:" +((TextMessage)message).getText());
     catch  (JMSException e) {
         e.printStackTrace();
     }
     }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package  com.liuy.mq.consumer.queue;
 
import  javax.jms.JMSException;
import  javax.jms.Message;
import  javax.jms.MessageListener;
import  javax.jms.TextMessage;
 
import  org.springframework.stereotype.Component;
 
/**
  * 队列消息监听器2
  * @description 队列消息监听器2
  * @author liuy
  * @version V1.00
  * @date:2017年4月12日上午10:15:19
  */
@Component
public  class  QueueReceiver2  implements  MessageListener {
 
     @Override
     public  void  onMessage(Message message) {
         try  {
         System.out.println( "QueueReceiver2接收到消息:" +((TextMessage)message).getText());
     catch  (JMSException e) {
         e.printStackTrace();
     }
     }
}

3.1.2 Topic消息监听器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package  com.liuy.mq.consumer.topic;
 
import  javax.jms.JMSException;
import  javax.jms.Message;
import  javax.jms.MessageListener;
import  javax.jms.TextMessage;
 
import  org.springframework.stereotype.Component;
 
/**
  * Topic消息监听器1
  * @description Topic消息监听器1
  * @author liuy
  * @version V1.00
  * @date:2017年4月12日上午10:17:11
  */
@Component
public  class  TopicReceiver1  implements  MessageListener{
 
 
     @Override
     public  void  onMessage(Message message) {
         try  {
         System.out.println( "TopicReceiver1接收到消息:" +((TextMessage)message).getText());
     catch  (JMSException e) {
         e.printStackTrace();
     }
     }
     
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package  com.liuy.mq.consumer.topic;
 
import  javax.jms.JMSException;
import  javax.jms.Message;
import  javax.jms.MessageListener;
import  javax.jms.TextMessage;
 
import  org.springframework.stereotype.Component;
 
/**
  * Topic消息监听器2
  * @description Topic消息监听器2
  * @author liuy
  * @version V1.00
  * @date:2017年4月12日上午10:17:11
  */
@Component
public  class  TopicReceiver2  implements  MessageListener{
 
 
     @Override
     public  void  onMessage(Message message) {
         try  {
             System.out.println( "TopicReceiver2接收到消息:" +((TextMessage)message).getText());
     catch  (JMSException e) {
         e.printStackTrace();
     }
     }
     
}

3.2 消息生产者

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package  com.liuy.mq.producer.queue;
 
import  javax.jms.JMSException;
import  javax.jms.Message;
import  javax.jms.Session;
 
import  org.springframework.beans.factory.annotation.Autowired;
import  org.springframework.beans.factory.annotation.Qualifier;
import  org.springframework.jms.core.JmsTemplate;
import  org.springframework.jms.core.MessageCreator;
import  org.springframework.stereotype.Component;
 
/**
  * 队列消息生产者,发送消息到队列
  * @description 队列消息生产者,发送消息到队列
  * @author liuy
  * @version V1.00
  * @date:2017年4月12日上午10:20:46
  */
@Component ( "queueSender" )
public  class  QueueSender {
     
     @Autowired
     @Qualifier ( "jmsQueueTemplate" )
     private  JmsTemplate jmsTemplate; //通过@Qualifier修饰符来注入对应的bean
     
     /**
      * 发送一条消息到指定的队列(目标)
      * @param queueName 队列名称
      * @param message 消息内容
      */
     public  void  send(String queueName, final  String message){
         jmsTemplate.send(queueName,  new  MessageCreator() {
             @Override
         public  Message createMessage(Session session)  throws  JMSException {
                 return  session.createTextMessage(message);
         }
         });
     }
     
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package  com.liuy.mq.producer.topic;
 
import  javax.jms.JMSException;
import  javax.jms.Message;
import  javax.jms.Session;
 
import  org.springframework.beans.factory.annotation.Autowired;
import  org.springframework.beans.factory.annotation.Qualifier;
import  org.springframework.jms.core.JmsTemplate;
import  org.springframework.jms.core.MessageCreator;
import  org.springframework.stereotype.Component;
 
/**
  * Topic生产者发送消息到Topic
  * @description Topic生产者发送消息到Topic
  * @author liuy
  * @version V1.00
  * @date:2017年4月12日上午10:20:46
  */
@Component ( "topicSender" )
public  class  TopicSender {
     @Autowired
     @Qualifier ( "jmsTopicTemplate" )
     private  JmsTemplate jmsTemplate;
     
     /**
      * 发送一条消息到指定的队列(目标)
      * @param queueName 队列名称
      * @param message 消息内容
      */
     public  void  send(String topicName, final  String message){
         jmsTemplate.send(topicName,  new  MessageCreator() {
         @Override
         public  Message createMessage(Session session)  throws  JMSException {
             return  session.createTextMessage(message);
         }
     });
     }
 
}

四、测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package  com.liuy.test.common;
 
import  org.junit.runner.RunWith;
import  org.springframework.test.context.ContextConfiguration;
import  org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
/**
  * 测试共公类
  * @description 测试共公类
  * @author liuy
  * @version V1.00
  * @date:2016年4月24日下午5:20:54
  */
@RunWith (SpringJUnit4ClassRunner. class )
@ContextConfiguration (locations =  "classpath:application-context.xml" )
public  class  SpringJunitTest 
{
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package  com.liuy.test.core;
 
import  org.junit.Test;
import  org.springframework.beans.factory.annotation.Autowired;
 
import  com.liuy.mq.producer.queue.QueueSender;
import  com.liuy.mq.producer.topic.TopicSender;
import  com.liuy.test.common.SpringJunitTest;
 
/**
  * @description 描述
  * @author liuy
  * @version 1.0
  * @date:2017年4月11日下午9:00:18
  */
public  class  SpringQueueTest  extends  SpringJunitTest {
     @Autowired 
     private  QueueSender queueSender;
     @Autowired 
     private  TopicSender topicSender;
     
     /**
      * 发送消息到队列
      * Queue队列:仅有一个订阅者会收到消息,消息一旦被处理就不会存在队列中
      * @param message
      * @return String
      */
     @Test
     public  void  testQueueSend()  throws  Exception {
         queueSender.send( "test.queue" "测试" );
     }
     
     /**
      * 发送消息到主题
      * Topic主题 :放入一个消息,所有订阅者都会收到 
      * 这个是主题目的地是一对多的
      * @param message
      * @return String
      */
     @Test
     public  void  testTopicSend()  throws  Exception {
         topicSender.send( "test.topic" "测试222" );
     }
}


效果:

 列队:

    wKioL1jtr5zRfnsxAAALOGTiKk8824.png

 主题:

    wKiom1jtr_TSyq09AAASyQz3W6U669.png

本文转自我爱大金子博客51CTO博客,原文链接http://blog.51cto.com/1754966750/1915190如需转载请自行联系原作者


我爱大金子

相关实践学习
5分钟轻松打造应对流量洪峰的稳定商城交易系统
本实验通过SAE极速部署一个微服务电商商城,同时结合RocketMQ异步解耦、削峰填谷的能力,带大家体验面对流量洪峰仍旧稳定可靠的商城交易系统!
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
相关文章
|
3月前
|
人工智能 Java 数据库
飞算 JavaAI:革新电商订单系统 Spring Boot 微服务开发
在电商订单系统开发中,传统方式耗时约30天,需应对复杂代码、调试与测试。飞算JavaAI作为一款AI代码生成工具,专注于简化Spring Boot微服务开发。它能根据业务需求自动生成RESTful API、数据库交互及事务管理代码,将开发时间缩短至1小时,效率提升80%。通过减少样板代码编写,提供规范且准确的代码,飞算JavaAI显著降低了开发成本,为软件开发带来革新动力。
|
3月前
|
前端开发 Java UED
从基础到进阶:Spring Boot + Thymeleaf 整合开发中的常见坑与界面优化
本文深入探讨了 **Spring Boot + Thymeleaf** 开发中常见的参数绑定问题与界面优化技巧。从基础的 Spring MVC 请求参数绑定机制出发,分析了 `MissingServletRequestParameterException` 的成因及解决方法,例如确保前后端参数名、类型一致,正确设置请求方式(GET/POST)。同时,通过实际案例展示了如何优化支付页面的视觉效果,借助简单的 CSS 样式提升用户体验。最后,提供了官方文档等学习资源,帮助开发者更高效地掌握相关技能。无论是初学者还是进阶用户,都能从中受益,轻松应对项目开发中的挑战。
114 0
|
22天前
|
Java API 微服务
Java 21 与 Spring Boot 3.2 微服务开发从入门到精通实操指南
《Java 21与Spring Boot 3.2微服务开发实践》摘要: 本文基于Java 21和Spring Boot 3.2最新特性,通过完整代码示例展示了微服务开发全流程。主要内容包括:1) 使用Spring Initializr初始化项目,集成Web、JPA、H2等组件;2) 配置虚拟线程支持高并发;3) 采用记录类优化DTO设计;4) 实现JPA Repository与Stream API数据访问;5) 服务层整合虚拟线程异步处理和结构化并发;6) 构建RESTful API并使用Springdoc生成文档。文中特别演示了虚拟线程配置(@Async)和StructuredTaskSco
85 0
|
3月前
|
人工智能 Java 定位技术
Java 开发玩转 MCP:从 Claude 自动化到 Spring AI Alibaba 生态整合
本文详细讲解了Java开发者如何基于Spring AI Alibaba框架玩转MCP(Model Context Protocol),涵盖基础概念、快速体验、服务发布与调用等内容。重点包括将Spring应用发布为MCP Server(支持stdio与SSE模式)、开发MCP Client调用服务,以及在Spring AI Alibaba的OpenManus中使用MCP增强工具能力。通过实际示例,如天气查询与百度地图路线规划,展示了MCP在AI应用中的强大作用。最后总结了MCP对AI开发的意义及其在Spring AI中的实现价值。
1135 9
|
4月前
|
消息中间件 存储 Java
微服务——SpringBoot使用归纳——Spring Boot中集成ActiveMQ——ActiveMQ安装
本教程介绍ActiveMQ的安装与基本使用。首先从官网下载apache-activemq-5.15.3版本,解压后即可完成安装,非常便捷。启动时进入解压目录下的bin文件夹,根据系统选择win32或win64,运行activemq.bat启动服务。通过浏览器访问`http://127.0.0.1:8161/admin/`可进入管理界面,默认用户名密码为admin/admin。ActiveMQ支持两种消息模式:点对点(Queue)和发布/订阅(Topic)。前者确保每条消息仅被一个消费者消费,后者允许多个消费者同时接收相同消息。
109 0
微服务——SpringBoot使用归纳——Spring Boot中集成ActiveMQ——ActiveMQ安装
|
3月前
|
人工智能 缓存 自然语言处理
保姆级Spring AI 注解式开发教程,你肯定想不到还能这么玩!
这是一份详尽的 Spring AI 注解式开发教程,涵盖从环境配置到高级功能的全流程。Spring AI 是 Spring 框架中的一个模块,支持 NLP、CV 等 AI 任务。通过注解(如自定义 `@AiPrompt`)与 AOP 切面技术,简化了 AI 服务集成,实现业务逻辑与 AI 基础设施解耦。教程包含创建项目、配置文件、流式响应处理、缓存优化及多任务并行执行等内容,助你快速构建高效、可维护的 AI 应用。
|
4月前
|
消息中间件 Java 微服务
微服务——SpringBoot使用归纳——Spring Boot中集成ActiveMQ——发布/订阅消息的生产和消费
本文详细讲解了Spring Boot中ActiveMQ的发布/订阅消息机制,包括消息生产和消费的具体实现方式。生产端通过`sendMessage`方法发送订阅消息,消费端则需配置`application.yml`或自定义工厂以支持topic消息监听。为解决点对点与发布/订阅消息兼容问题,可通过设置`containerFactory`实现两者共存。最后,文章还提供了测试方法及总结,帮助读者掌握ActiveMQ在异步消息处理中的应用。
139 0
|
4月前
|
消息中间件 网络协议 Java
微服务——SpringBoot使用归纳——Spring Boot中集成ActiveMQ——ActiveMQ集成
本文介绍了在 Spring Boot 中集成 ActiveMQ 的详细步骤。首先通过引入 `spring-boot-starter-activemq` 依赖并配置 `application.yml` 文件实现基本设置。接着,创建 Queue 和 Topic 消息类型,分别使用 `ActiveMQQueue` 和 `ActiveMQTopic` 类完成配置。随后,利用 `JmsMessagingTemplate` 实现消息发送功能,并通过 Controller 和监听器实现点对点消息的生产和消费。最后,通过浏览器访问测试接口验证消息传递的成功性。
124 0

热门文章

最新文章