springboot 学习笔记(六)
(六)springboot整合activemq
1、现下载activemq,下载链接:http://activemq.apache.org/download.html,windows系统解压后进入bin目录,分32位、64位操作系统,运行activemq.bat启动程序,访问http://http://127.0.0.1:8161
出现该界面说明安装成功,点击broker,输入账号admin 密码admin 进入管理界面
点击queue按钮,可以创建消息队列。
2、pom文件中增加以下依赖,在application.properties对activema进行配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
#访问地址
spring.activemq.broker-url=tcp://127.0.0.1:61616
spring.activemq.user=admin
spring.activemq.password=admin
#是否开启线程池
spring.activemq.pool.enabled=true
#最大连接数
spring.activemq.pool.max-connections=50
3、在Application.class中添加如下代码,方便注入队列
package com.zc.app.test; 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; @SpringBootApplication
public class TestApplication {
@Bean
public Queue queue(){
return new ActiveMQQueue("test.queue");
}
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
} }
TestApplication
4、新建一个service接口用来发送消息,并实现发送消息
/**
*
*/
package com.zc.app.test.service; import javax.jms.Destination; public interface MsgService { public void sendMessage(Destination destination,String message); public void sendMessage(String message);
}
MsgService
/**
*
*/
package com.zc.app.test.service.impl; import javax.jms.Destination;
import javax.jms.Queue; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service; import com.zc.app.test.service.MsgService; @Service
public class MsgServiceImpl implements MsgService{ @Autowired
private Queue queue; @Autowired
private JmsMessagingTemplate jms; //用来发送消息 @Override
public void sendMessage(Destination destination,String message) {
jms.convertAndSend(this.queue, message); } @Override
public void sendMessage(String message) {
jms.convertAndSend(message); } }
MsgServiceImpl
5、写controller来调用接口
/**
*
*/
package com.zc.app.test.controller; import javax.jms.Destination; import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.zc.app.test.service.MsgService; @RestController
@RequestMapping("/msg")
public class SendController { @Autowired
private MsgService msgService; @GetMapping("send")
public String order(String message) { Destination destination = new ActiveMQQueue("test.queue");
msgService.sendMessage(destination, message);
return "send message success";
}
}
SendController
6、启动程序,这时程序出现错误,提示JmsMessagingTemplate注入失败
Field jms in com.zc.app.test.service.impl.MsgServiceImpl required a bean of type 'org.springframework.jms.core.JmsMessagingTemplate' that could not be found.
7、通过测试,将acticemq线程池配置删除后,程序可以正常启动,最后找到原因是因为少了jms的pool依赖包,在pom文件添加以下依赖后可以正常启动
<dependency>
<groupId>org.messaginghub</groupId>
<artifactId>pooled-jms</artifactId>
</dependency>
8、然后访问url:localhost:8080/msg/send?message=124515,提示成功后,可以从activemq的管理界面看到test.queue消息增加
springboot 学习笔记(六)的更多相关文章
- Springboot学习笔记(六)-配置化注入
前言 前面写过一个Springboot学习笔记(一)-线程池的简化及使用,发现有个缺陷,打个比方,我这个线程池写在一个公用服务中,各项参数都定死了,现在有两个服务要调用它,一个服务的线程数通常很多,而 ...
- java之jvm学习笔记六-十二(实践写自己的安全管理器)(jar包的代码认证和签名) (实践对jar包的代码签名) (策略文件)(策略和保护域) (访问控制器) (访问控制器的栈校验机制) (jvm基本结构)
java之jvm学习笔记六(实践写自己的安全管理器) 安全管理器SecurityManager里设计的内容实在是非常的庞大,它的核心方法就是checkPerssiom这个方法里又调用 AccessCo ...
- SpringBoot学习笔记
SpringBoot个人感觉比SpringMVC还要好用的一个框架,很多注解配置可以非常灵活的在代码中运用起来: springBoot学习笔记: .一.aop: 新建一个类HttpAspect,类上添 ...
- Learning ROS for Robotics Programming Second Edition学习笔记(六) indigo xtion pro live
中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...
- Typescript 学习笔记六:接口
中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...
- python3.4学习笔记(六) 常用快捷键使用技巧,持续更新
python3.4学习笔记(六) 常用快捷键使用技巧,持续更新 安装IDLE后鼠标右键点击*.py 文件,可以看到Edit with IDLE 选择这个可以直接打开编辑器.IDLE默认不能显示行号,使 ...
- Go语言学习笔记六: 循环语句
Go语言学习笔记六: 循环语句 今天学了一个格式化代码的命令:gofmt -w chapter6.go for循环 for循环有3种形式: for init; condition; increment ...
- SpringBoot学习笔记(14):使用SpringBootAdmin管理监控你的应用
SpringBoot学习笔记(14):使用SpringBootAdmin管理监控你的应用 Spring Boot Admin是一个管理和监控Spring Boot应用程序的应用程序.本文参考文档: 官 ...
- SpringBoot学习笔记(3):静态资源处理
SpringBoot学习笔记(3):静态资源处理 在web开发中,静态资源的访问是必不可少的,如:Html.图片.js.css 等资源的访问. Spring Boot 对静态资源访问提供了很好的支持, ...
- SpringBoot学习笔记(2):引入Spring Security
SpringBoot学习笔记(2):用Spring Security来保护你的应用 快速开始 本指南将引导您完成使用受Spring Security保护的资源创建简单Web应用程序的过程. 参考资料: ...
随机推荐
- Tournament
题意: 有 $n$ 个 $K$ 维向量,若向量A只要有任意一维大于向量B,则认为A可能打败B,将n个向量一个一个加入,求问对于每次加完后的向量集合:有几个向量可能活到最后. 解法: 考虑如果A可以打败 ...
- 业务逻辑:完成客户下单后前台系统的数据处理并调用后台系统服务处理业务 webservice接口调用 有用
思路: 页面提交表单后,在Action类中将页面提交的参数进行组装,随后通过使用Webservice技术来远程调用后台系统的业务接口服务来进行订单的保存操作 操作步骤: 在前台系统的Action类中通 ...
- npm设置代理提高下载速度
*nix上给网络类程序设置代理的通用办法,即导出http_proxy/https_proxy环境变量对npm不起作用 需要用npm自己的配置命令来解决: npm set proxy $PROXY np ...
- 菜鸟大充电啦啦啦啦啦:eclipse SDK 是什么啊
为什么下载是,没有单独的ecipse呢,,总是eclipse-sdk呢 而且还很大几百兆 回复1: Eclipse有好多专用名称,例如Eclipse SDK等.先说一下SDK, Eclipse Pro ...
- JS中双击和单击事件冲突解决
在JS中代码中同一功能块中通常同时会用到单击.双击事件,但通常会遇到一个问题,就是在双击的时候即执行了一次双击事件,而且还执行了两次单击事件.此类冲突在ZTree.DHTMLX中经常遇到. 想要解决两 ...
- javascript函数自执行里的this为什么指向window
当你要确定“函数中的this是什么”的时候,永远不要到函数定义的地方去找答案!而是要到函数被调用的地方找答案! 具体说:函数里面的this的含义,是由它被调用的方式决定的. 换句话说,当你看到下面的代 ...
- spring-cloud 服务优雅下线
在集群环境下,zuul后面的api服务一般会有多个实例,当下线某个实例时,如果使用 kill -9 pid 的方式,会造成这个服务在eureka中还存在,请求还会路由到这个服务上面,造成500,所 ...
- Android 设计模式情景分析——观察者模式
观察者模式是一种使用频率非常高的模式,有时也被称作发布/订阅模式,属于行为型模式,它最常用的是 GUI 系统.订阅——发布系统,它一个重要作用就是解耦,使得它们之间的依赖性更小.观察者模式定义了对象间 ...
- linux网络基础-网卡bonding技术
1.bondingbonding(绑定)是一种linux系统下的网卡绑定技术,可以把服务器上n个物理网卡在系统内部抽象(绑定)成一个逻辑上的网卡,实现本地网卡的冗余,带宽扩容和负载均衡.在应用部署中是 ...
- servlet之doPost()、doGet()
1.doGet和doPost方法的具体应用?即在什么时候程序调用doGet方法,什么时候程序执行doPost方法? HttpServlet是从GenericServlet继承而来,因此HttpServ ...