上篇博客带来的是spring boot + redis实现session共享的文章,这次给大家带来的是spring boot + activemq。
首先,我在github上找到了一个不错的demo,这里放给大家一起看下:
确实可以实现功能,但是当我在8161默认的admin端口进行queue查询时,发现并没有我们的github-queue,虽然不太清楚具体的原因,但是解决方式倒是找到了,下面贴一下自己的实现:
pox.xml:
<!-- ActiveMQ --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>5.13.2</version> </dependency>
application.properties:
spring.activemq.in-memory=true spring.activemq.pooled=false
接下来就是jms的配置了,首先是ActiveMQ4Config文件:
@EnableJms @Configuration public class ActiveMQ4Config { @Bean public Queue queue() { return new ActiveMQQueue("github-queue"); } @Bean public ActiveMQConnectionFactory activeMQConnectionFactory (){ ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory( ActiveMQConnectionFactory.DEFAULT_USER, ActiveMQConnectionFactory.DEFAULT_PASSWORD, // "tcp://192.168.0.100:61616"); ActiveMQConnectionFactory.DEFAULT_BROKER_URL); return activeMQConnectionFactory; } }
注释掉的那行,可以用来指定activemq的broker地址。
接下来的Producer和Consumer与github上一样:
@Component public class Producer implements CommandLineRunner{ @Autowired private JmsMessagingTemplate jmsMessagingTemplate; @Autowired private Queue queue; @Override public void run(String... args) throws Exception { send("this message is send on begining!"); System.out.println("Message was sent to the Queue"); } public void send(String msg) { this.jmsMessagingTemplate.convertAndSend(this.queue, msg); } }
@Component public class Consumer { @JmsListener(destination = "github-queue") public void receiveQueue(String text) { System.out.println(text); } }
这样一来就完成了配置,而且在8161默认admin进行查询时,是能够查询到我们的github-queue这个队列的。
具体的测试,可以自己进行,这里不再贴测试用例了。
相关推荐
SpringBoot+ActiveMq+MQTT实现消息的发送和接收 后台消费者、生产者、消息发送接口、发送消息业务类等相关配置
springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot...
基于Springboot+ActiveMQ事务==本地事件表+activemq,即利用activemq+本地事件表实现分布式事务的功能
微服务架构面试题系列:Dubbo+Spring Boot+Spring Cloud+Nginx+ActiveMQ+RabbitMQ+Kafka
springboot整合mybatis+activemq(activemq可以去官网下载
NULL 博文链接:https://yaozhiqiang109.iteye.com/blog/1073455
spring boot activemq集成示例,包含queue和topic消息的发送、接收,连接池的支持。
spring boot 集成activemq Datajpa Ehcache 里面有详细的例子
SpringBoot整合ActiveMQ+websocket.docx ,该文档包含于activemq整合的各个情况,springboot,js,websocket与mq整合,该资源是上传代码的word文档部分
本项目基于Spring boot这一平台,整合流行的开源消息队列中间件ActiveMQ,实现一个向ActiveMQ添加和读取消息的功能。分别实现生产者-消费者模式和发布-订阅模式,作为java编程发送消息和消费消息的基础示例。 源码...
spring boot ActiveMQ学习练习demo项目源码;包含text,map,byte,stream,object5种类型信息的发送和接收
Nepxion Thunder是一款基于Netty + Hessian + Kafka + ActiveMQ + Tibco + Zookeeper(Curator Framework) + Redis + FST + Spring + Spring Web MVC + Spring Boot + Docker分布式RPC调用框架。架构思想主要是来自...
Spring boot 和内置ActiveMQ集成例子,通过代码学习Spring boot 和内置ActiveMQ集成。
Spring Boot 做的一个简单的增删改查,前台页面整合Thymeleaf模板,数据源druid,声明式事务,整合redis,并开启redis事务,整合ActiveMQ
本书围绕秒杀抢购应用场景 ,对当下...主要内容包括微服务架构介绍、 Dub box 原理及运用、使用 Spring Boot实现微服务 使用 ActiveMQ Redis 承载高兴二发流量、使用 ctiveMQ 实现分布式事务 分布式下的 第三方接入等。
spring-boot-activemq-consumer 源码
spring boot activemq整合例子
spring-boot-activemq-producer 源码
spring-boot 集成activemq代码demo
SpringBoot快速玩转ActiveMQ消息队列,jdk8下的简要版介绍。