SpringBoot-ActiveMq
来源:互联网 发布:如何做数据透视表 编辑:程序博客网 时间:2024/05/29 11:27
ActiveMq下载:
http://activemq.apache.org
下载解压安装,打开安装目录下的bin/win64/activemq:
浏览器输入 http://localhost:8161/,能进入主页面表明安装成功:
maven依赖:
<dependency><groupId>org.springframework</groupId><artifactId>spring-jms</artifactId></dependency><dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-client</artifactId></dependency>
消息定义:
package com.example.demo;import org.springframework.jms.core.MessageCreator;import javax.jms.JMSException;import javax.jms.Message;import javax.jms.Session;public class Msg implements MessageCreator{ @Override public Message createMessage(Session session) throws JMSException { return session.createTextMessage("这是测试消息"); }}
消息发送及地址定义:
package com.example.demo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.CommandLineRunner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.jms.core.JmsTemplate;@SpringBootApplicationpublic class DemoApplication implements CommandLineRunner{@Autowired//注入springboot为我们配置好的JmsTemplate的beanJmsTemplate jmsTemplate;public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}@Overridepublic void run(String... strings) throws Exception {//向my-destination目的地发送MSG消息jmsTemplate.send("my-destination",new Msg());}}消息监听:
package com.example.demo;import org.springframework.jms.annotation.JmsListener;import org.springframework.stereotype.Component;@Componentpublic class Receiver { @JmsListener(destination = "my-destination") public void receiveMsg(String msg){ System.out.println("接收到的消息:"+msg); }}运行:
遇到的问题:
1.关闭activeMq后,再次启动Tomcat,报错:
Caused by: java.net.ConnectException: Connection refused: connect
2.使用springboot的内嵌 activemq,启动Tomcat报错:
<dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-broker</artifactId></dependency>Caused by: java.net.ConnectException: Connection refused: connect
阅读全文
0 0
- SpringBoot-ActiveMq
- springboot activemq
- [ActiveMQ][SpringBoot]SpringBoot中集成ActiveMQ
- SpringBoot集成ActiveMQ
- Springboot集成activemq
- springboot、mybatis、activemq整合
- SpringBoot 整合 Apache ActiveMQ
- springboot集成activeMQ
- springboot整合activeMQ
- SpringBoot集成ActiveMQ
- springboot整合activemq
- SpringBoot-ActiveMQ(一)
- Springboot整合ActiveMQ
- SpringBoot 集成 activeMQ
- springboot集成activemq,超赞!!!
- springboot整合多个activemq
- SpringBoot使用JavaConfig配置ActiveMQ
- SpringBoot 整合ActiveMQ 小Demo
- 解决Activity中或fragment时,点击手机返回键无效,无法触发onKeyDown
- Git-项目推送到github和clone到本地(笔记)
- 无法在 DLL SqlServerSpatial110.dll 中找到名为 SetClrFeatureSwitchMap 解决方法
- 学习笔记27-哈弗曼树
- .NET题120道
- SpringBoot-ActiveMq
- IDEA 操作
- sdbtop使用介绍
- C++ SQL语句 执行失败
- 《高性能MYSQL》第一章 MySQL架构与历史
- Hiernate(5)——缓存策略的概述
- (9)返回xml格式数据,但是用户却收到“该公众号提供的服务出现故障,请稍后再试”
- 解决子元素设置浮动影响父元素问题
- SpringMVC中解决@ResponseBody注解返回中文乱码问题