QueueUtil
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; public class QueueUtil { private static Logger logger = LoggerFactory.getLogger(QueueUtil.class); private static Connection connection = null;
private static String QUEUE_NAME = null; static {
if (connection == null) {
initConnection();
}
} private QueueUtil() {
} private static void initConnection() {
try {
ConnectionFactory factory = new ConnectionFactory();
String host = PropertiesUtil.RABBITMQ_HOST;
logger.info("RabbitMQ Server IP :{}", host);
factory.setHost(host);
int port = PropertiesUtil.RABBITMQ_PORT;
logger.info("RabbitMQ Server Port :{}", port);
factory.setPort(port);
String username = PropertiesUtil.RABBITMQ_USERNAME;
factory.setUsername(username);
String password = PropertiesUtil.RABBITMQ_PASSWORD;
factory.setPassword(password);
QUEUE_NAME = PropertiesUtil.RABBITMQ_QUEUE_NAME;
logger.info("RabbitMQ Server queue name :{}", QUEUE_NAME);
connection = factory.newConnection();
} catch (Exception e) {
logger.error("队列出错",e);
}
} public static Connection getConnection() {
if (connection == null) {
initConnection();
}
return connection;
} public static String getQueueName() {
return QUEUE_NAME;
}
}
QueueUtil的更多相关文章
- rabbitMq创建和获取消息
package com.yunda.inter.preload.contextinit; import net.sf.json.JSONObject; import org.apache.common ...
- 基于数组阻塞队列 ArrayBlockingQueue 的一个队列工具类
java语言基于ArrayBlockingQueue 开发的一个根据特定前缀和后缀的队列.每天自动循环生成. 1.定义队列基类 Cookie package com.bytter.util.queue ...
随机推荐
- bzoj 3232: 圈地游戏 01分数规划
题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3232 题解: 首先我们看到这道题让我们最优化一个分式. 所以我们应该自然而然地想到01分 ...
- Unity3d中SendMessage 用法
Message相关有3条指令:SendMessage ("函数名",参数,SendMessageOptions) //GameObject自身的ScriptBroadcastM ...
- S3C2410中文芯片手册-11.串口
目录 11 UART Overview Featrues UART Operation Data Transmission Data Reception Auto Flow Control(AFC) ...
- node-webkit开发基本步骤
详情请查看:http://www.heiboard.com/?p=2091
- bzoj 4816 数字表格 —— 反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4816 推导过程同:http://www.cnblogs.com/zhouzhendong/p ...
- oracle rac搭建
(一)环境准备 主机操作系统 windows10 虚拟机平台 vmware workstation 12 虚拟机操作系统 redhat 5.5 x86(32位) :Linux.5.5.for.x86. ...
- POJ 2017 No Brainer(超级水题)
一.Description Zombies love to eat brains. Yum. Input The first line contains a single integer n indi ...
- virtual judge(专题一 简单搜索 C)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- Python:内置函数zip()
zip函数接受任意多个可迭代对象作为参数,将对象中对应的元素打包成一个tuple,然后返回一个可迭代的zip对象. 这个可迭代对象可以使用循环的方式列出其元素 若多个可迭代对象的长度不一致,则所返回的 ...
- Guice 学习
Guice: 是一个轻量级的DI框架. 不需要繁琐的配置,只需要定义一个Module来表述接口和实现类,以及父类和子类之间的关联关系的绑定,如下是一个例子. http://blog.csdn.net/ ...