Spring Boot 2.0.0.M7 使用异步消息服务-JMS(ActiveMQ)
2018-01-12 07:41
531 查看
使用异步消息服务-JMS(ActiveMQ)
Spring Boot支持的jms有:ActiveMQ、Artemis、HornetQ
添加依赖
<!-- jms --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> </dependency>
配置文件
# 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队列配置 * */ @Configuration publicclass JmsConfiguration { @Bean publicQueue queue() { returnnew ActiveMQQueue("ctoedu.queue"); } }
@Component publicclass 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"); }
相关文章推荐
- (十七)SpringBoot之使用异步消息服务jms之ActiveMQ
- 使用apache的activemq集合JMS处理异步消息
- Spring Boot 2.0.0.M7 使用异步消息服务-AMQP(RabbitMQ)
- ActiveMQ使用spring JmsTemplate发送消息(一)
- MSMQ?不,太弱了。使用ActiveMQ实现消息队列服务
- 使用Spring JMS轻松实现异步消息传递
- 使用Spring JMS轻松实现异步消息传递
- JMS消息服务入门讲解,基于ActiveMQ的实现【基础篇】
- 1.异步消息Jms及其JmsTemplate的源代码分析,消息代理ActiveMQ
- ActiveMQ使用spring JmsTemplate发送消息(一)
- jms消息服务使用
- JAVA JMS Java消息服务(Java Message Service) 的实现ActiveMQ
- 使用Spring JMS轻松实现异步消息传递
- ActiveMQ使用spring JmsTemplate发送消息(一)
- 使用Spring JMS简化异步消息处理
- 使用Spring JMS简化异步消息处理
- ActiveMQ编写JMS(Java消息服务)实例分享
- 使用Spring JMS简化异步消息处理
- 本篇主要讲解在未使用其他框架(Spring)整合情况下,独立基于ActiveMQ,使用JMS规范进行消息通信。
- ActiveMQ使用spring JmsTemplate发送消息(一)