package com.moral.util;
|
|
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Connection;
|
import com.rabbitmq.client.ConnectionFactory;
|
|
public class RabbitMQUtils {
|
private static ConnectionFactory factory ;
|
|
static{
|
factory = new ConnectionFactory();
|
factory.setHost("47.96.15.25");//设置连接地址
|
factory.setPort(5672);//设置端口
|
factory.setUsername("guest");
|
factory.setPassword("guest_pass");
|
factory.setVirtualHost("/");//设置虚拟主机
|
}
|
|
public static Connection getConnection(){
|
try{
|
return factory.newConnection();
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
public static void closeConnectionChannel(Connection connection, Channel channel){
|
try{
|
if(channel!=null)
|
channel.close();
|
if(connection!=null)
|
connection.close();
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
public static void closeChannel( Channel channel){
|
try{
|
if(channel!=null)
|
channel.close();
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
}
|