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应用程序的过程. 参考资料: ...
随机推荐
- win10系统-javac不是内部或外部命令
给笔记本装了一个ssd,上午装的系统,重新搞jdk,设置JAVA_HOME之后,cmd运行javac报 “javac不是内部或外部命令”各种懵逼,试了好几次才发现Path路径里面不能用%JAVA_HO ...
- 洛谷-铺地毯-NOIP2011提高组复赛
题目描述 为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有 n 张地毯,编号从 1 到n .现在将这些地毯按照编号从小到大的顺序平行于 ...
- 杭电acm 1049题
一道水题..... 大意是一条1inch的虫子在一个n inch的盒子的底部,有足够的能够每一分钟往上爬u inch,但是需要休息一分钟,这期间会往下掉d inch,虫子爬到盒子口即认为结束.要求计算 ...
- php学习笔记-php中把浮点数转化为整数
在php中有时候会遇到比如 14.6%3这种操作,php是会先把14.6转化为整数再做其它的操作,那么这个转化为整数的操作是floor(14.6)还是ceil(14.6)还是round(14.6)呢? ...
- 使用jquery插件实现图片延迟加载--懒加载技术
原文链接:http://www.cnblogs.com/lei2007/archive/2013/05/31/3110725.html 感谢作者.以下为原文,备忘仅供自己学习. 第一:lazyLoad ...
- Instruments10 分析某个类中方法的执行时间
此步骤也可用户内存分配.内存泄漏的检测 最新操作步骤参考: https://www.jianshu.com/p/e499ce63ed72
- 微信H5支付----报undened index openid
1.检查传过来的订单号是否是恒定不变的 2.检查总价是否为整数(微信要求订单金额是整数).以及不能为0 以下是这次错误的具体原因: 主要是前面读取的金额数据需要读取接口的,而不是数据库的(接口读取的是 ...
- Codeforces Beta Round #71 C【KMP+DP】
Codeforces79C 题意: 求s串的最大子串不包含任意b串: 思路: dp[i]为以i为起点的子串的最长延长距离. 我们可以想到一种情况就是这个 i 是某个子串的起点,子串的长度-1就是最短, ...
- 反射实现增删改查(DAO层)——插入数据
先贴出代码,后续补充自己的思路.配置文件.使用方式: /** * 插入数据 */ @Override public void addObject(Object object, String table ...
- 799C(xjb)
题目链接: http://codeforces.com/problemset/problem/799/C 题意: 有c, d两种货币, 有 n 个货物, 可以用 c 货币或者 d 货币购买, 现在需要 ...