Spring Boot + ActiveMq
来源:互联网 发布:深圳云计算招聘岗位 编辑:程序博客网 时间:2024/06/13 23:26
下载activeMq:http://activemq.apache.org/activemq-5152-release.html
启动activeMq:bin目录下activemq.bat直接启动
http://localhost:8161进入activemq首页
pom.xml引入activeMq插件
<!-- activemq --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> </dependency>
application.properties配置
# ACTIVEMQ (ActiveMQProperties)spring.activemq.broker-url= # URL of the ActiveMQ broker. Auto-generated by default. For instance `tcp://localhost:61616`spring.activemq.in-memory=true # Specify if the default broker URL should be in memory. Ignored if an explicit broker has been specified.spring.activemq.password= # Login password of the broker.spring.activemq.user= # Login user of the broker.spring.activemq.packages.trust-all=false # Trust all packages.spring.activemq.packages.trusted= # Comma-separated list of specific packages to trust (when not trusting all packages).spring.activemq.pool.configuration.*= # See PooledConnectionFactory.spring.activemq.pool.enabled=false # Whether a PooledConnectionFactory should be created instead of a regular ConnectionFactory.spring.activemq.pool.expiry-timeout=0 # Connection expiration timeout in milliseconds.spring.activemq.pool.idle-timeout=30000 # Connection idle timeout in milliseconds.spring.activemq.pool.max-connections=1 # Maximum number of pooled connections.
这里主要涉及到几个角色,消息生产者,消息队列,消息消费者。所以只需要把这个解决实现了,编码也就完成了。
消息队列Queue,这里编写在启动类App.java中,以@Bean的方式注入:
package com.kfit;import javax.jms.Queue;import org.apache.activemq.command.ActiveMQQueue;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.Bean;/** * * @author Angel --YYR * @version v.0.1 */@SpringBootApplicationpublic class App { @Bean public Queue queue() { return new ActiveMQQueue("sample.queue"); } public static void main(String[] args) { SpringApplication.run(App.class, args); }}
在这里注入了一个ActiveMQQueue。消息生产者com.kfit.demo.Producer:
package com.kfit.demo;import javax.jms.Queue;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.jms.core.JmsMessagingTemplate;import org.springframework.scheduling.annotation.EnableScheduling;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;/** * 消息生产者. * @author Angel --YYR * @version v.0.1 */@Component@EnableSchedulingpublic class Producer { @Autowired private JmsMessagingTemplate jmsMessagingTemplate; @Autowired private Queue queue; @Scheduled(fixedDelay=3000)//每3s执行1次 public void send() { this.jmsMessagingTemplate.convertAndSend(this.queue, "hi,activeMQ"); }}
这里使用JmsMessagingTemplate 进行消息的操作,然后使用任务调度3秒1次执行消息的发布。消息消费者com.kfit.demo.Consumer:
package com.kfit.demo;import org.springframework.jms.annotation.JmsListener;import org.springframework.stereotype.Component;/** * 消息消费者. * @author Angel YYR * @version v.0.1 */@Componentpublic class Consumer { @JmsListener(destination = "sample.queue") public void receiveQueue(String text) { System.out.println(text); }}
这里主要是加入了@JmsListener进行监听,然后接收消息然后打印。
阅读全文
0 0
- spring boot jms activemq
- spring-boot集成ActiveMQ
- spring-boot 集成 activemq
- spring-boot 集成 activemq
- spring boot整合activemq
- spring boot集成activemq
- spring boot集成ActiveMQ
- Spring boot 集成Activemq
- Spring boot 整个 ActiveMQ
- spring boot activeMQ 配置
- Spring Boot + ActiveMq
- spring-boot集成activemq
- spring boot ActiveMQ学习
- spring boot的ActiveMQ使用
- spring boot整合activemq rabbitmq
- (八)Spring Boot整合ActiveMQ
- Spring Boot与ActiveMQ整合
- 86. Spring Boot集成ActiveMQ【从零开始学Spring Boot】
- codeforces 485D. Maximum Value
- ON1 Photo RAW 2017(RAW格式图片处理工具)官方正式版V12.0.0.4006下载 | on1 photo raw 破解版下载
- RxJava(二:Observable 创建,组合与过滤)
- 添加子菜单
- 3.spring IOC、DI 介绍
- Spring Boot + ActiveMq
- 【转】前端跨域知识总结
- 机器学习入门:线性回归及梯度下降
- 在OpenCV中使用RANSAC
- 【Kill】两条Linux命令彻底杀死Oracle
- jenkins 最简单部署配置
- jquery各种验证......
- 程序员经常争论的话题:C++/JAVA/C#运行机制和执行效率
- unix socket编程