安装单机rabbitmq
 
1.安装erlang
cd /usr.local
yum install wget
yum install net-tools
wget http://erlang.org/download/otp_src_19.3.tar.g
解压
tar -xvzf otp_src_19.3.tar.gz
 
erlang在安装前需要先安装下它的依赖工具:
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC-devel
 
然后进入解压文件对erlang进行安装环境的配置(为了以后升级版本,此处就继续使用加压文件的名字了,至少我看得懂。。。。)
./configure --prefix=/usr/erlang --without-javac 
 
编译make
 
安装 make install
 
验证是否安装成功
./bin/erl
 
配置环境变量
vi /etc/profile
在最后加:export PATH=$PATH:/usr/local/otp_src_19.3/bin
source /etc/profile
 
2.安装RabbitMQ
 
yum install rabbitmq-server-3.6.6-1.el7.noarch.rpm
 
可能会报错
erlang >= R16B-03
解决方法
yum -y install socat
yum -y install epel-release
再进入 usr/local
yum install rabbitmq-server-3.6.6-1.el7.noarch.rpm
 
完成后启动服务:
service rabbitmq-server start
可以查看服务状态
service rabbitmq-server status
 
 
这里可以看到log文件的位置,转到文件位置,打开文件:
 
这里显示的是没有找到配置文件,我们可以自己创建这个文件
 
cd /etc/rabbitmq/ vi rabbitmq.config
 
编辑内容如下:
[{rabbit, [{loopback_users, []}]}].
 
保存配置后重启服务:
service rabbitmq-server stop service rabbitmq-server start
 
 
开启管理UI:
rabbitmq-plugins enable rabbitmq_management firewall-cmd --zone=public --add-port=15672/tcp --permanent firewall-cmd --reload
 
在Windows下打开地址:
 
 
 
至此 rabbitmq安装成功
 
应用
 
首页看下目录结构
 
这是个springboot项目,
spring-rabbitmq.xml:配置mq的所有基本信息
rabbit文件夹下的xml即配置的exchange,routingkey以及对应绑定的对列名
listener包下是所需要的监听类
主要是以下内容
@RabbitListener(queues = "attendance.q") :监听的队列名
@RabbitHandler 对应监听的方法
如何去发送:定义exchange和routeingkey就ok了
 
public class RabbitUtil {

    @Autowired
private ConnectionFactory connectionFactory; @Autowired
private RabbitTemplate rabbitTemplate; private static RabbitUtil rabbitUtil; @PostConstruct
private void init() {
rabbitUtil = this;
rabbitUtil.rabbitTemplate = this.rabbitTemplate;
rabbitUtil.connectionFactory = this.connectionFactory;
} public static RabbitTemplate getRabbitTemplate() {
return rabbitUtil.rabbitTemplate;
} public static ConnectionFactory getConnectionFactory() {
return rabbitUtil.connectionFactory;
} /**
* 发送RMQ消息
*
* @param message
* @throws AmqpException
*/
public void convertAndSend(String message) throws AmqpException {
convertAndSend(null, null, message, false);
} /**
* 发送RMQ消息
*
* @param routingKey
* @param message
* @throws AmqpException
*/
public void convertAndSend(String routingKey, String message) throws AmqpException {
convertAndSend(null, routingKey, message, false);
} /**
* 发送RMQ消息
*
* @param exchange
* @param routingKey
* @param message
* @throws AmqpException
*/
public static void convertAndSend(String exchange, String routingKey, String message) throws AmqpException {
convertAndSend(exchange, routingKey, message, false);
} private static void convertAndSend(String exchange, String routingKey, Object message, boolean waitForAck)
throws AmqpException {
if (waitForAck) { } else {
if (StringUtils.isNotEmpty(exchange) && StringUtils.isNotEmpty(routingKey)) {
getRabbitTemplate().convertAndSend(exchange, routingKey, message);
} else if (StringUtils.isNotEmpty(routingKey)) {
getRabbitTemplate().convertAndSend(routingKey, message);
} else {
getRabbitTemplate().convertAndSend(message);
}
}
} /**
* 查询队列消息数量
* @param queue
* @throws Exception
*/
public static long getMessageCount(String queue) throws Exception {
Connection connection = null;
Channel channel = null;
try {
ConnectionFactory connectionFactory = getConnectionFactory();
connection = connectionFactory.createConnection();
channel = connection.createChannel(false);
return channel.messageCount(queue);
} finally {
if(channel != null){
channel.close();
}
if(connection != null){
connection.close();
}
} }
 

centos7 rabbitmq安装以及应用的更多相关文章

  1. centos7 rabbitmq安装/配置

    原文:centos7 rabbitmq安装/配置     因为RabbitMQ是由erlang实现的,所以要先安装erlang再安装rabbitMQ   1.先配置yum软件源地址EPEL(EPEL是 ...

  2. Linux(CENTOS7) RabbitMq安装

    RabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.它遵循Mozilla Public License开源协议,采用 Erlang 实现的工业级的消息队列(MQ)服务器,Rab ...

  3. centos7 rabbitmq 安装

    http://www.rabbitmq.com/install-rpm.html Overview rabbitmq-server is included in Fedora. However, th ...

  4. 使用专业的消息队列产品rabbitmq之centos7环境安装

      我们在项目开发的时候都不可避免的会有异步化的问题,比较好的解决方案就是使用消息队列,可供选择的队列产品也有很多,比如轻量级的redis, 当然还有重量级的专业产品rabbitmq,rabbitmq ...

  5. [转]centos7环境安装rabbitMQ

    使用专业的消息队列产品rabbitmq之centos7环境安装 http://www.cnblogs.com/huangxincheng/p/6006569.html CentOS7上安装Rabbit ...

  6. RabbitMQ消息队列(三)-Centos7下安装RabbitMQ3.6.1

    如果你看过前两章对RabbitMQ已经有了一定了解,现在已经摩拳擦掌,来吧动手吧! 用什么系统 本文使用的是Centos7,为了保证对linux不太熟悉的伙伴也能轻松上手(避免折在安装的路上),下面是 ...

  7. 【rabbitmq】Centos7 下安装rabbitmq

    rabbitmq安装 rabbitmq的安装依赖erlang,首先应该先安装erlang,然后安装rabbitmq: Step1:安装erlang erlang-rpm安装教程 选择在Centos7 ...

  8. centos7下安装rabbitmq

    RabbitMQ: RabbitMQ是流行的开源消息队列系统,是AMQP(Advanced Message Queuing Protocol高级消息队列协议)的标准实现,用erlang语言开发.Rab ...

  9. centos7环境安装rabbitMQ

    使用专业的消息队列产品rabbitmq之centos7环境安装 http://www.cnblogs.com/huangxincheng/p/6006569.html [源码安装,适用GNOME + ...

随机推荐

  1. zabbix监控windows系统CPU使用率

    参考网站:https://blog.csdn.net/reblue520/article/details/76287113 Zabbix 自带的模块没有 CPU 使用率(百分比)这个监控项,我们可以通 ...

  2. leetcode937

    public class Solution { public string[] ReorderLogFiles(string[] logs) { var list1 = new List<str ...

  3. leetcode107

    /** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...

  4. eclipse中创建多模块maven web项目

    本文讲述在eclipse中创建分模块maven web项目. 暂时将一个项目分为controller:service:dao以及父类模块四部分. 1.创建父类模块. 创建一个简单的maven proj ...

  5. How to Pronounce PROBABLY

    How to Pronounce PROBABLY Share Tweet Share Though this is a content word, it’s frequently reduced. ...

  6. linux——DNS服务器配置

    讲课,请不要在课堂上查找文件,浏览器搜索,会感觉你很不上心,玩听众,一定提前做很多遍,模拟很多遍: 演讲,请务必准备好材料,考虑听众的感受,一定不要让外行人云里雾里,听不懂你在讲什么,那就尴尬了, D ...

  7. 进化的Spark, 从DataFrame说起

    进化的Spark, 从DataFrame说起:http://www.tuicool.com/articles/IzeY7zM

  8. Nsis Sqlite Plugin

    1.https://stackoverflow.com/questions/15346338/nsis-and-sqlite-integration 2.http://nsis.sourceforge ...

  9. PR数量回写重复

  10. javascript基础代码

    1.点击改变HTML内容 <html> <head> <meta charset="UTF-8"> <script> functio ...