liunx 安装ActiveMQ 及 spring boot 初步整合 activemq
源码地址: https://gitee.com/kevin9401/microservice.git
一、安装 ActiveMQ:
1. 下载 ActiveMQ
wget https://archive.apache.org/dist/activemq/5.14.0/apache-activemq-5.14.0-bin.tar.gz

2. 解压 并且重命名 为 activemq
tar -zxvf apache-activemq-5.14.0-bin.tar.gz && mv apache-activemq-5.14.0 activemq


3. 配置环境变量(不做也行,暂时没发现用处)
vim /etc/profile
添加
export ACTIVEMQ_HOME=/usr/local/softwares/activemq
export PATH=:$JAVA_HOME/bin:$ACTIVEMQ_HOME/bin:$PATH

使配置生效:
source /etc/profile
4. 进入目录,启动 activemq
cd /usr/local/softwares/activemq/bin/linux-x86-64

执行
./activemq start

5. 访问
ip:8161
点击 Manage ActiveMQ broker


6. 如果要输入用户名、密码,默认的是 admin/admin

【备注】 如果访问不了,应该是被防火墙阻挡了,可以选择 关闭防火墙,或者在放行列表中 添加 8161(web管理页面端口)、61616(activemq服务监控端口) 两个端口
如果防火墙是开启的:
打开linux防火墙端口
/sbin/iptables -I INPUT -p tcp --dport 8161 -j ACCEPT&&/etc/init.d/iptables save&&service iptables restart&&/etc/init.d/iptables status
/sbin/iptables -I INPUT -p tcp --dport 61616 -j ACCEPT&&/etc/init.d/iptables save&&service iptables restart&&/etc/init.d/iptables status
二、spring boot 整合 activemq
1. 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

2. 创建消息队列对象
@Configuration
public class QueueConfig { /**
* 创建 名称为 active.queue 的消息队列对象
*
* @return
*/
@Bean
public Queue queue() {
return new ActiveMQQueue("active.queue1");
}
}

3. 创建消息生产者
@RestController
public class QueueController { @Autowired
private JmsMessagingTemplate messagingTemplate; @Autowired
private Queue queue; /**
* 消息生产者
*/
@RequestMapping(value = "/send")
public void send() {
messagingTemplate.convertAndSend(queue, "hello world");
}
}
4. 在 application.yml 中配置连接
spring:
activemq:
broker-url: tcp://ip:61616

5. 启动项目,调用发送消息接口

6. 查看消息队列

参考:https://www.cnblogs.com/shamo89/p/7645651.html
------------恢复内容开始------------
源码地址:
一、安装 ActiveMQ:
1. 下载 ActiveMQ
wget https://archive.apache.org/dist/activemq/5.14.0/apache-activemq-5.14.0-bin.tar.gz

2. 解压 并且重命名 为 activemq
tar -zxvf apache-activemq-5.14.0-bin.tar.gz && mv apache-activemq-5.14.0 activemq


3. 配置环境变量(不做也行,暂时没发现用处)
vim /etc/profile
添加
export ACTIVEMQ_HOME=/usr/local/softwares/activemq
export PATH=:$JAVA_HOME/bin:$ACTIVEMQ_HOME/bin:$PATH

使配置生效:
source /etc/profile
4. 进入目录,启动 activemq
cd /usr/local/softwares/activemq/bin/linux-x86-64

执行
./activemq start

5. 访问
ip:8161
点击 Manage ActiveMQ broker


6. 如果要输入用户名、密码,默认的是 admin/admin

【备注】 如果访问不了,应该是被防火墙阻挡了,可以选择 关闭防火墙,或者在放行列表中 添加 8161(web管理页面端口)、61616(activemq服务监控端口) 两个端口
如果防火墙是开启的:
打开linux防火墙端口
/sbin/iptables -I INPUT -p tcp --dport 8161 -j ACCEPT&&/etc/init.d/iptables save&&service iptables restart&&/etc/init.d/iptables status
/sbin/iptables -I INPUT -p tcp --dport 61616 -j ACCEPT&&/etc/init.d/iptables save&&service iptables restart&&/etc/init.d/iptables status
二、spring boot 整合 activemq
1. 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

2. 创建消息队列对象
@Configuration
public class QueueConfig { /**
* 创建 名称为 active.queue 的消息队列对象
*
* @return
*/
@Bean
public Queue queue() {
return new ActiveMQQueue("active.queue1");
}
}

3. 创建消息生产者
@RestController
public class QueueController { @Autowired
private JmsMessagingTemplate messagingTemplate; @Autowired
private Queue queue; /**
* 消息生产者
*/
@RequestMapping(value = "/send")
public void send() {
messagingTemplate.convertAndSend(queue, "hello world");
}
}
4. 在 application.yml 中配置连接
spring:
activemq:
broker-url: tcp://ip:61616

5. 启动项目,调用发送消息接口

6. 查看消息队列

参考:https://www.cnblogs.com/shamo89/p/7645651.html
------------恢复内容结束------------
liunx 安装ActiveMQ 及 spring boot 初步整合 activemq的更多相关文章
- elasticsearch 的安装配置与spring boot的整合应用
linux上的elasticsearch安装 一.下载elasticsearch 直接进入elasticsearch的官网,下载最新的安装包:https://www.elastic.co/downlo ...
- Spring Boot 监听 Activemq 中的特定 topic ,并将数据通过 RabbitMq 发布出去
1.Spring Boot 和 ActiveMQ .RabbitMQ 简介 最近因为公司的项目需要用到 Spring Boot , 所以自学了一下, 发现它与 Spring 相比,最大的优点就是减少了 ...
- 【ActiveMQ】2.spring Boot下使用ActiveMQ
在spring boot下使用ActiveMQ,需要一下几个条件 1.安装并启动了ActiveMQ,参考:http://www.cnblogs.com/sxdcgaq8080/p/7919489.ht ...
- Spring Boot Security 整合 JWT 实现 无状态的分布式API接口
简介 JSON Web Token(缩写 JWT)是目前最流行的跨域认证解决方案.JSON Web Token 入门教程 - 阮一峰,这篇文章可以帮你了解JWT的概念.本文重点讲解Spring Boo ...
- Spring boot Mybatis 整合(完整版)
个人开源项目 springboot+mybatis+thymeleaf+docker构建的个人站点开源项目(集成了个人主页.个人作品.个人博客) 朋友自制的springboot接口文档组件swagge ...
- Spring boot Mybatis 整合
PS: 参考博客 PS: spring boot配置mybatis和事务管理 PS: Spring boot Mybatis 整合(完整版) 这篇博客里用到了怎样 生成 mybatis 插件来写程 ...
- spring boot 学习(二)spring boot 框架整合 thymeleaf
spring boot 框架整合 thymeleaf spring boot 的官方文档中建议开发者使用模板引擎,避免使用 JSP.因为若一定要使用 JSP 将无法使用. 注意:本文主要参考学习了大神 ...
- Spring Boot 应用系列 5 -- Spring Boot 2 整合logback
上一篇我们梳理了Spring Boot 2 整合log4j2的配置过程,其中讲到了Spring Boot 2原装适配logback,并且在非异步环境下logback和log4j2的性能差别不大,所以对 ...
- Spring boot Mybatis 整合(注解版)
之前写过一篇关于springboot 与 mybatis整合的博文,使用了一段时间spring-data-jpa,发现那种方式真的是太爽了,mybatis的xml的映射配置总觉得有点麻烦.接口定义和映 ...
随机推荐
- 大一C语言学习笔记(4)---自省篇
博主"曾经"做过的傻事: #你有的*没打全 #你用/的时候没考虑()是一对的 #printf随后加\n #所有变量只要用,就一定要定义数据类型 #sqrt()代表根号 #inclu ...
- React-Router示例(重定向与withRouter)
1.withRouter作用:把不是通过路由切换过来的组件中,将react-router 的 history.location.match 三个对象传入props对象上 默认情况下必须是经过路由匹 ...
- 【数据结构】【图文】【oj习题】 图的拓扑排序(邻接表)
拓扑排序: 按照有向图给出的次序关系,将图中顶点排成一个线性序列,对于有向图中没有限定次序关系的顶点,则可以人为加上任意的次序关系,由此所得顶点的线性序列称之为拓扑有序序列.显然对于有回路的有向图得不 ...
- PAT A1020——已知后序中序遍历求层序遍历
1020 Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Give ...
- Web优化躬行记(5)——网站优化
最近阅读了很多优秀的网站性能优化的文章,所以自己也想总结一些最近优化的手段和方法. 个人感觉性能优化的核心是:减少延迟,加速展现. 本文主要从产品设计.前端.后端和网络四个方面来诉说优化过程. 一.产 ...
- JS中bind、call和apply的作用以及在TS装饰器中的用法
目录 1,前言 1,call 1.1,例子 1.2,直接调用 1.3,将this指向另一个对象 1.4,传递参数 2,apply 2.1,例子 2.2,直接调用 2.3,将this指向另一个对象 2. ...
- [bzoj3170]松鼠聚会
这个距离就是切比雪夫距离,有一个神奇的东西是说将(x,y)变成(x+y,x-y),然后就是曼哈顿距离,因此转化后对x坐标和y坐标分别统计排序和求和(求前缀和预处理+二分) 1 #include< ...
- 手把手教你实现Android真机远程截屏
先看效果演示 接下来手把手教你实现这样的效果. minicap简介 minicap是一个可以远程获取android屏幕画面的开源库,它在低版本的Android系统上采用截屏的方式获取画面,在Andro ...
- 大厂技术实现 | 腾讯信息流推荐排序中的并联双塔CTR结构 @推荐与计算广告系列
作者:韩信子@ShowMeAI,Joan@腾讯 地址:http://www.showmeai.tech/article-detail/tencent-ctr 声明:版权所有,转载请联系平台与作者并注明 ...
- SSM整合小项目
1.文件目录结构 2.MyBatis配置 创建数据库环境 CREATE DATABASE `ssmbuild`; USE `ssmbuild`; DROP TABLE IF EXISTS `books ...