...
|
...
|
@@ -66,6 +66,22 @@ public class DirectUtils { |
|
|
return connection;
|
|
|
}
|
|
|
|
|
|
public Connection getConnection(String hostIp, int hostPort, String vHostName) throws Exception
|
|
|
{
|
|
|
//定义连接工厂
|
|
|
ConnectionFactory factory = new ConnectionFactory();
|
|
|
//设置服务地址
|
|
|
factory.setHost(hostIp);
|
|
|
//端口
|
|
|
factory.setPort(hostPort);
|
|
|
//设置账号信息,用户名、密码、vhost
|
|
|
factory.setVirtualHost(vHostName);
|
|
|
factory.setUsername(username);
|
|
|
factory.setPassword(password);
|
|
|
// 通过工程获取连接
|
|
|
return factory.newConnection();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 链接 RabbitMQ
|
|
|
*
|
...
|
...
|
@@ -232,11 +248,17 @@ public class DirectUtils { |
|
|
return directProducer(xmlData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送消息,使用中
|
|
|
* @param xmlData {@link XmlData}
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public ResultJson directProducer(XmlData xmlData) throws Exception
|
|
|
{
|
|
|
// 1、创建Connection
|
|
|
Connection connection = getConnection(xmlData.getServerIp(), xmlData.getServerPort(),
|
|
|
xmlData.getVirtualHostName(), xmlData.getSender(), xmlData.getPassword());
|
|
|
xmlData.getVirtualHostName());
|
|
|
// 2、 通过Connection创建一个新的Channel
|
|
|
Channel channel = connection.createChannel();
|
|
|
// 3、开启消息的确认机制(confirm:保证消息能够发送到 exchange)
|
...
|
...
|
|