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