作者 王勇

修改生存消息的规则(改用MQ超级的超级管理员的用户名和密码来建立连接)

... ... @@ -39,6 +39,12 @@ public class RabbitController {
@Resource
private AsyncTaskService asyncTaskService;
/**
* 测试时的消费消息
*
* @throws IOException
* @throws TimeoutException
*/
@GetMapping("/test/consumer")
public void consumer() throws IOException, TimeoutException
{
... ...
... ... @@ -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)
... ...
... ... @@ -50,6 +50,7 @@ public class ResultJson<T> implements Serializable {
{
}
/**
* 定义有参构造器
*
... ... @@ -94,6 +95,12 @@ public class ResultJson<T> implements Serializable {
return new ResultJson<>("200", "success");
}
public static ResultJson success(String msg)
{
return new ResultJson<>("200", msg);
}
/**
* 定义静态、成功方法(重载)
*
... ...
package com.sunyo.wlpt.message.bus.service.utils;
import java.security.MessageDigest;
/**
* @author 子诚
* Description:
* 时间:2020/8/7 17:33
*/
public class Md5Utils {
/***
* MD5加码 生成32位md5码
*/
public static String string2Md5(String inStr)
{
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
return "";
}
char[] charArray = inStr.toCharArray();
byte[] byteArray = new byte[charArray.length];
for (int i = 0; i < charArray.length; i++) {
byteArray[i] = (byte) charArray[i];
}
byte[] md5Bytes = md5.digest(byteArray);
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < md5Bytes.length; i++) {
int val = ((int) md5Bytes[i]) & 0xff;
if (val < 16) {
hexValue.append("0");
}
hexValue.append(Integer.toHexString(val));
}
return hexValue.toString();
}
/**
* 加密解密算法 执行一次加密,两次解密
*/
public static String convertMD5(String inStr)
{
char[] a = inStr.toCharArray();
for (int i = 0; i < a.length; i++) {
a[i] = (char) (a[i] ^ 't');
}
String s = new String(a);
return s;
}
}
... ...
... ... @@ -141,7 +141,8 @@ public class XmlUtils {
}
// 获取密码
xmlData.setPassword(userList.get(0).getPassword());
// xmlData.setPassword(userList.get(0).getPassword());
// 获取服务器ip
xmlData.setServerPort(serverList.get(0).getServerPort());
// 获取服务器port
... ...