上篇博客带来的是spring boot + redis实现session共享的文章,这次给大家带来的是spring boot + activemq。
首先,我在github上找到了一个不错的demo,这里放给大家一起看下:
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-activemq
确实可以实现功能,但是当我在8161默认的admin端口进行queue查询时,发现并没有我们的github-queue,虽然不太清楚具体的原因,但是解决方式倒是找到了,下面贴一下自己的实现:
pox.xml:
org.springframework spring-jms org.apache.activemq activemq-all 5.13.2
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上一样: