博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot 2.0.0.M7 使用异步消息服务-JMS(ActiveMQ)
阅读量:3724 次
发布时间:2019-05-22

本文共 1230 字,大约阅读时间需要 4 分钟。

使用异步消息服务-JMS(ActiveMQ)

Spring Boot支持的jms有:ActiveMQ、Artemis、HornetQ

添加依赖

org.springframework.boot
spring-boot-starter-activemq

配置文件

# ACTIVEMQ (ActiveMQProperties)spring.activemq.in-memory=true#spring.activemq.broker-url= #spring.activemq.password= #spring.activemq.user= #spring.activemq.packages.trust-all=false#spring.activemq.packages.trusted=#spring.activemq.pool.configuration.*= #spring.activemq.pool.enabled=false#spring.activemq.pool.expiry-timeout=0#spring.activemq.pool.idle-timeout=30000#spring.activemq.pool.max-connections=1

代码实现

启动注解:

  • @EnableJms 添加在main方法里面

配置队列

/** * jms队列配置 *  */@Configurationpublicclass JmsConfiguration {	@Bean	publicQueue queue() {		returnnew ActiveMQQueue("ctoedu.queue");	}}
@Componentpublicclass JmsComponent {	@Autowired	private JmsMessagingTemplate jmsMessagingTemplate;		@Autowired	private Queue queue;	publicvoid send(String msg) {		this.jmsMessagingTemplate.convertAndSend(this.queue, msg);	}		@JmsListener(destination = "ctoedu.queue")	publicvoid receiveQueue(String text) {		System.out.println("接受到:" + text);	}}

测试

@Autowired	private JmsComponent jmsComponent;	@Test	public void send() {		jmsComponent.send("hello world");	}

转载地址:http://sxonn.baihongyu.com/

你可能感兴趣的文章
程序设计:引爆炸弹 (计蒜客 - A1139)
查看>>
2020年第十一届蓝桥杯模拟赛解题报告
查看>>
Mysql单表查询的基本操作
查看>>
Mysql基本操作
查看>>
Mysql单表查询例题详解
查看>>
java——安装JDK及配置解决常见问题
查看>>
java类、封装、继承
查看>>
数据库程序设计(毕业选题系统)
查看>>
算法(分治、贪心、dp、回溯、分支限界)总结
查看>>
Java数据类型
查看>>
Jungle Roads(最小生成树)
查看>>
最短路径问题(HDU3790)
查看>>
构造器(有参、无参)
查看>>
Java运算符
查看>>
Java包机制及JavaDoc
查看>>
数据库原理——绪论
查看>>
数据库原理—关系数据库
查看>>
虚拟机(vmware)中安装linux系统
查看>>
Python—海龟作图
查看>>
进制转换(m 进制 x 转换为 n 进制的数)
查看>>