[ActiveMQ][SpringBoot]SpringBoot中集成ActiveMQ
来源:互联网 发布:亚马逊好还是淘宝好 编辑:程序博客网 时间:2024/05/29 11:29
配置条件:
springboot:
yml,
gradle;
在springboot项目中使用activemq,首先gradle(本人的项目是用gradle管理的,maven同理)中的build.gradle引入activemq依赖
compile "org.springframework.boot:spring-boot-starter-activemq"compile "org.springframework:spring-jms"
yml中的配置:
activemq: broker-url: tcp://你的activemq地址:你的activemq端口 user: 你的activemq管理账号 password: 你的activemq管理账号密码 in-memory: true pool: enabled: false
在springboot启动类Application中加入需要使用的的队列名,并且开启Jms
@EnableJms@SpringBootApplicationpublic class RestapiApplication { //就是这里嘛 @Bean public Queue queue() { return new ActiveMQQueue("sample.queue"); } public static void main(String[] args) { SpringApplication.run(RestapiApplication.class, args); }}
activemq的controller,这里简单做个使用demo,主要是方面大家用postman进行队列消息生产;
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.jms.core.JmsMessagingTemplate;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import javax.jms.Queue;@RequestMapping(value = "/jms")@RestControllerpublic class ActiveMQController { @Autowired private JmsMessagingTemplate jmsMessagingTemplate; @Autowired private Queue queue; //这里就是队列消息生产,方便使用postman测试 @RequestMapping("/sendMsg") public void send(String msg) { this.jmsMessagingTemplate.convertAndSend(this.queue, msg); }}
ok,接下来写个测试用的消费者
import org.springframework.jms.annotation.JmsListener;import org.springframework.stereotype.Component;@Componentpublic class Consumer { //JmsListener注解监听队列 @JmsListener(destination = "sample.queue") public void receiveQueue(String text) { System.out.println(text); }}
ok,生产者,消费者,springboot配置都ok;
使用postman测试吧
一个,超级精简的Activemq入门;
阅读全文
0 0
- [ActiveMQ][SpringBoot]SpringBoot中集成ActiveMQ
- SpringBoot集成ActiveMQ
- Springboot集成activemq
- springboot集成activeMQ
- SpringBoot集成ActiveMQ
- SpringBoot 集成 activeMQ
- springboot集成activemq,超赞!!!
- SpringBoot-ActiveMq
- springboot activemq
- springboot 系统学习5 集成 activemq
- springboot、mybatis、activemq整合
- SpringBoot 整合 Apache ActiveMQ
- springboot整合activeMQ
- springboot整合activemq
- SpringBoot-ActiveMQ(一)
- Springboot整合ActiveMQ
- 【Demo】springboot微服务+activemq消息中间件集成
- springboot整合多个activemq
- 【arduino】u8glib库资料整理
- 通过Id获取资源
- 解决VS2017报错fopen、sprintf等函数安全的问题
- 配置Docker使用Convoy存储插件
- Docker实践,利用DaoCloud来部署应用
- [ActiveMQ][SpringBoot]SpringBoot中集成ActiveMQ
- equals和==
- matlab GUI 打包成exe可执行文件的方法(2016b)
- 每天一个linux命令(16):which命令
- 常用缩写及其含义
- CCPC FINAL 2017(Inkopolis-基环外向树)
- 生活艰难
- spark入门笔记
- 每天一个linux命令(17):whereis 命令