Springboot整合ActiveMQ(Queue和Topic两种模式),Java知识总结

本文介绍了如何在Springboot项目中整合ActiveMQ,详细阐述了Queue和Topic两种模式的配置与使用。通过创建队列生产者和消费者,以及topic生产者,展示了消息的发送和接收过程。配置包括ActiveMQ服务器地址、用户认证和消息模式设置。此外,还提供了相关的配置类和控制器代码示例。
摘要由CSDN通过智能技术生成

springboot-mq

0.0.1-SNAPSHOT

springboot-mq

Demo project for Spring Boot

<java.version>1.8</java.version>

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-activemq

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

org.springframework.boot

spring-boot-maven-plugin

2、项目结构

3、相关配置信息

在application.properties类中添加ActiveMQ相关的配置信息

server.port=8080

server.servlet.context-path=/mq

#MQ服务器地址

spring.activemq.broker-url=tcp://localhost:61616

#用户名

spring.activemq.user=admin

#密码

spring.activemq.password=admin

#设置是Queue队列还是Topic,false为Queue,true为Topic,默认false-Queue

spring.jms.pub-sub-domain=false

#spring.jms.pub-sub-domain=true

#变量,定义队列和topic的名称

myqueue: activemq-queue

mytopic: activemq-topic

4、ActiveMQ配置类

ActiveMQ配置类ConfigBean,配置了Queue队列和topic两种模式,代码如下:

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.jms.annotation.EnableJms;

import org.springframework.stereotype.Componen

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值