centos7 rabbitmq安装以及应用








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安装以及应用的更多相关文章
- centos7 rabbitmq安装/配置
原文:centos7 rabbitmq安装/配置 因为RabbitMQ是由erlang实现的,所以要先安装erlang再安装rabbitMQ 1.先配置yum软件源地址EPEL(EPEL是 ...
- Linux(CENTOS7) RabbitMq安装
RabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.它遵循Mozilla Public License开源协议,采用 Erlang 实现的工业级的消息队列(MQ)服务器,Rab ...
- centos7 rabbitmq 安装
http://www.rabbitmq.com/install-rpm.html Overview rabbitmq-server is included in Fedora. However, th ...
- 使用专业的消息队列产品rabbitmq之centos7环境安装
我们在项目开发的时候都不可避免的会有异步化的问题,比较好的解决方案就是使用消息队列,可供选择的队列产品也有很多,比如轻量级的redis, 当然还有重量级的专业产品rabbitmq,rabbitmq ...
- [转]centos7环境安装rabbitMQ
使用专业的消息队列产品rabbitmq之centos7环境安装 http://www.cnblogs.com/huangxincheng/p/6006569.html CentOS7上安装Rabbit ...
- RabbitMQ消息队列(三)-Centos7下安装RabbitMQ3.6.1
如果你看过前两章对RabbitMQ已经有了一定了解,现在已经摩拳擦掌,来吧动手吧! 用什么系统 本文使用的是Centos7,为了保证对linux不太熟悉的伙伴也能轻松上手(避免折在安装的路上),下面是 ...
- 【rabbitmq】Centos7 下安装rabbitmq
rabbitmq安装 rabbitmq的安装依赖erlang,首先应该先安装erlang,然后安装rabbitmq: Step1:安装erlang erlang-rpm安装教程 选择在Centos7 ...
- centos7下安装rabbitmq
RabbitMQ: RabbitMQ是流行的开源消息队列系统,是AMQP(Advanced Message Queuing Protocol高级消息队列协议)的标准实现,用erlang语言开发.Rab ...
- centos7环境安装rabbitMQ
使用专业的消息队列产品rabbitmq之centos7环境安装 http://www.cnblogs.com/huangxincheng/p/6006569.html [源码安装,适用GNOME + ...
随机推荐
- zabbix监控windows系统CPU使用率
参考网站:https://blog.csdn.net/reblue520/article/details/76287113 Zabbix 自带的模块没有 CPU 使用率(百分比)这个监控项,我们可以通 ...
- leetcode937
public class Solution { public string[] ReorderLogFiles(string[] logs) { var list1 = new List<str ...
- leetcode107
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...
- eclipse中创建多模块maven web项目
本文讲述在eclipse中创建分模块maven web项目. 暂时将一个项目分为controller:service:dao以及父类模块四部分. 1.创建父类模块. 创建一个简单的maven proj ...
- How to Pronounce PROBABLY
How to Pronounce PROBABLY Share Tweet Share Though this is a content word, it’s frequently reduced. ...
- linux——DNS服务器配置
讲课,请不要在课堂上查找文件,浏览器搜索,会感觉你很不上心,玩听众,一定提前做很多遍,模拟很多遍: 演讲,请务必准备好材料,考虑听众的感受,一定不要让外行人云里雾里,听不懂你在讲什么,那就尴尬了, D ...
- 进化的Spark, 从DataFrame说起
进化的Spark, 从DataFrame说起:http://www.tuicool.com/articles/IzeY7zM
- Nsis Sqlite Plugin
1.https://stackoverflow.com/questions/15346338/nsis-and-sqlite-integration 2.http://nsis.sourceforge ...
- PR数量回写重复
- javascript基础代码
1.点击改变HTML内容 <html> <head> <meta charset="UTF-8"> <script> functio ...