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的映射配置总觉得有点麻烦.接口定义和映 ...
随机推荐
- 【完虐算法】LeetCode 接雨水问题,全复盘
大家好! 动态规划题目是总结的比较完整了.下面是自从和大家刷开题总结的动态规划解题方法. 今年全国夏天雨是真的多,突然想到今年北京的夏天也不像往年那么热.不知不觉就稳稳地度过了夏天来到秋天. 恰巧前几 ...
- Spring Cache 带你飞(二)
接着上一篇讲了 Spring Cache 如何被 Spring Aop 代理加载对应的代码,以及何如注入相关界面逻辑. Spring Cache 带你飞(一) 本篇我们围绕两个要点展开: 一个数据是如 ...
- 设计系统(Design System),设计和开发之间的“DevOps”
最近,我们网站的上新增了几个新功能,比如通过导航栏的QR Code可以下载App:通过Carousel的方式,显示多条信息. 以往这样的功能可能需要2-3个Sprints完成,但是现在这些功能都是在一 ...
- 个人网站迁移之旅:从博客到知识库,从 Hexo 到 Docusaurus
或是出于跟风,或是为了简历能好看点,2020 年 2 月,在翻看了中文互联网大量的「免费个人网页搭建教程」后,我选择了 Hexo + Github Pages 的方案,找了一款看上去还不错的主题,搭建 ...
- SpringBoot 整合 Mybatis-Plus + Mysql
mybatis-plus是mybatis的一款插件,它的主要作用是快速开发,省略mybatis的配置,具体的功能请参照官网. 开发环境: springboot,maven,mybatis-plus,m ...
- Part 61 to 63 Talking about partial class and partial method in C#
部分类和部分方法 部分类是用partial声明的类,它允许我们把一个类分割成两个或多个类,当应用程序编译的完成的时候,多个部分类会结合成一个类,同时partial关键字也可以用于声明结构和接口. 那么 ...
- 从零开始制作一个linux iso镜像
一.前言 对于一个极简化的linux系统而言,只需要三个部分就能组成,它们分别是一个linux内核.一个根文件系统和引导.以下是本文制作linux iso镜像所用到的系统和软件: OS ...
- MAC VMware fusion 12.1.0 Centos7 网络配置
虚拟机选择NAT模式 获取mac机器中vmnet8的gateway地址 找到 # NAT gateway address这一行,下面的ip就是gateway地址 cat /Library/Prefer ...
- [bzoj1280]卖猪
首先考虑猪无法流动,那么源点向每一个猪圈连猪圈中猪个数的边,每一个顾客向汇点连所需猪的边,每一个猪圈向能打开它的顾客连inf的边,跑最大流即可. 但考虑猪要流动,有一个十分巧妙地做法,将每一个顾客所有 ...
- [bzoj1741]穿越小行星群
将每一行/每一列作为一个点,对于一个障碍(x,y),要么第x行和第y列的状态(是否攻击)只需要有一个就可以了,将第x行和第y列连边,就是二分图的最小点覆盖=最大匹配数. 1 #include<b ...