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 + ...
随机推荐
- linux装机首先需要关闭的服务
关闭selinux和iptables:setenforce 0 iptables -Fiptables -t nat -Fsystemctl stop firewalldsystemctl disab ...
- Mybatis like模糊查询的写法
转自:http://blog.51cto.com/lavasoft/1386870 Mybatis like查询官方文档没有明确的例子可循,网上搜索了很多,都不正确. Mybatis 3.2.6经过尝 ...
- ajax 实现跨域
ajax本身是不可以跨域的,通过产生一个script标签来实现跨域.因为script标签的src属性是没有跨域的限制的. 其实设置了dataType: 'jsonp'后,$.ajax方法就和ajax ...
- is not on any development teams
is not on any development teams 1)账号正在申请中 2)申请成功后的账号? 加了3个账号,都是这样子的. 1:Xcode>Window> "Org ...
- display:inline、block、inline-block区别
display:inline.block.inline-block区别 display:block就是将元素显示为块级元素. display:inline就是将元素显示为行内元素. inline-bl ...
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)--(转)
图像: 1.图片浏览控件MWPhotoBrowser 实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作. 下 ...
- Gearman简介
gearman,从名字上看叫做“齿轮工”,就是通过齿轮把不同的组件组合在一起.通常,多语言多系统之间的集成是项目开发中一个比较头疼的问题.一般会采用RPC风格或者是REST风格的WebService. ...
- DateUtil日期处理
package com.zjx.util; import java.text.SimpleDateFormat; import java.util.Date; public class DateUti ...
- asp.net cors solution
I have a simple actionmethod, that returns some json. It runs on ajax.example.com. I need to access ...
- ubuntu 软件包系统已损坏 解决方法
sudo apt-get clean sudo apt-get -f install sudo apt-get upgrade