正在显示
5 个修改的文件
包含
93 行增加
和
2 行删除
| @@ -39,6 +39,12 @@ public class RabbitController { | @@ -39,6 +39,12 @@ public class RabbitController { | ||
| 39 | @Resource | 39 | @Resource |
| 40 | private AsyncTaskService asyncTaskService; | 40 | private AsyncTaskService asyncTaskService; |
| 41 | 41 | ||
| 42 | + /** | ||
| 43 | + * 测试时的消费消息 | ||
| 44 | + * | ||
| 45 | + * @throws IOException | ||
| 46 | + * @throws TimeoutException | ||
| 47 | + */ | ||
| 42 | @GetMapping("/test/consumer") | 48 | @GetMapping("/test/consumer") |
| 43 | public void consumer() throws IOException, TimeoutException | 49 | public void consumer() throws IOException, TimeoutException |
| 44 | { | 50 | { |
| @@ -66,6 +66,22 @@ public class DirectUtils { | @@ -66,6 +66,22 @@ public class DirectUtils { | ||
| 66 | return connection; | 66 | return connection; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | + public Connection getConnection(String hostIp, int hostPort, String vHostName) throws Exception | ||
| 70 | + { | ||
| 71 | + //定义连接工厂 | ||
| 72 | + ConnectionFactory factory = new ConnectionFactory(); | ||
| 73 | + //设置服务地址 | ||
| 74 | + factory.setHost(hostIp); | ||
| 75 | + //端口 | ||
| 76 | + factory.setPort(hostPort); | ||
| 77 | + //设置账号信息,用户名、密码、vhost | ||
| 78 | + factory.setVirtualHost(vHostName); | ||
| 79 | + factory.setUsername(username); | ||
| 80 | + factory.setPassword(password); | ||
| 81 | + // 通过工程获取连接 | ||
| 82 | + return factory.newConnection(); | ||
| 83 | + } | ||
| 84 | + | ||
| 69 | /** | 85 | /** |
| 70 | * 链接 RabbitMQ | 86 | * 链接 RabbitMQ |
| 71 | * | 87 | * |
| @@ -232,11 +248,17 @@ public class DirectUtils { | @@ -232,11 +248,17 @@ public class DirectUtils { | ||
| 232 | return directProducer(xmlData); | 248 | return directProducer(xmlData); |
| 233 | } | 249 | } |
| 234 | 250 | ||
| 251 | + /** | ||
| 252 | + * 发送消息,使用中 | ||
| 253 | + * @param xmlData {@link XmlData} | ||
| 254 | + * @return | ||
| 255 | + * @throws Exception | ||
| 256 | + */ | ||
| 235 | public ResultJson directProducer(XmlData xmlData) throws Exception | 257 | public ResultJson directProducer(XmlData xmlData) throws Exception |
| 236 | { | 258 | { |
| 237 | // 1、创建Connection | 259 | // 1、创建Connection |
| 238 | Connection connection = getConnection(xmlData.getServerIp(), xmlData.getServerPort(), | 260 | Connection connection = getConnection(xmlData.getServerIp(), xmlData.getServerPort(), |
| 239 | - xmlData.getVirtualHostName(), xmlData.getSender(), xmlData.getPassword()); | 261 | + xmlData.getVirtualHostName()); |
| 240 | // 2、 通过Connection创建一个新的Channel | 262 | // 2、 通过Connection创建一个新的Channel |
| 241 | Channel channel = connection.createChannel(); | 263 | Channel channel = connection.createChannel(); |
| 242 | // 3、开启消息的确认机制(confirm:保证消息能够发送到 exchange) | 264 | // 3、开启消息的确认机制(confirm:保证消息能够发送到 exchange) |
| @@ -50,6 +50,7 @@ public class ResultJson<T> implements Serializable { | @@ -50,6 +50,7 @@ public class ResultJson<T> implements Serializable { | ||
| 50 | { | 50 | { |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | + | ||
| 53 | /** | 54 | /** |
| 54 | * 定义有参构造器 | 55 | * 定义有参构造器 |
| 55 | * | 56 | * |
| @@ -94,6 +95,12 @@ public class ResultJson<T> implements Serializable { | @@ -94,6 +95,12 @@ public class ResultJson<T> implements Serializable { | ||
| 94 | return new ResultJson<>("200", "success"); | 95 | return new ResultJson<>("200", "success"); |
| 95 | } | 96 | } |
| 96 | 97 | ||
| 98 | + public static ResultJson success(String msg) | ||
| 99 | + { | ||
| 100 | + return new ResultJson<>("200", msg); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + | ||
| 97 | /** | 104 | /** |
| 98 | * 定义静态、成功方法(重载) | 105 | * 定义静态、成功方法(重载) |
| 99 | * | 106 | * |
| 1 | +package com.sunyo.wlpt.message.bus.service.utils; | ||
| 2 | + | ||
| 3 | +import java.security.MessageDigest; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author 子诚 | ||
| 7 | + * Description: | ||
| 8 | + * 时间:2020/8/7 17:33 | ||
| 9 | + */ | ||
| 10 | +public class Md5Utils { | ||
| 11 | + | ||
| 12 | + /*** | ||
| 13 | + * MD5加码 生成32位md5码 | ||
| 14 | + */ | ||
| 15 | + public static String string2Md5(String inStr) | ||
| 16 | + { | ||
| 17 | + MessageDigest md5 = null; | ||
| 18 | + try { | ||
| 19 | + md5 = MessageDigest.getInstance("MD5"); | ||
| 20 | + } catch (Exception e) { | ||
| 21 | + System.out.println(e.toString()); | ||
| 22 | + e.printStackTrace(); | ||
| 23 | + return ""; | ||
| 24 | + } | ||
| 25 | + char[] charArray = inStr.toCharArray(); | ||
| 26 | + byte[] byteArray = new byte[charArray.length]; | ||
| 27 | + | ||
| 28 | + for (int i = 0; i < charArray.length; i++) { | ||
| 29 | + byteArray[i] = (byte) charArray[i]; | ||
| 30 | + } | ||
| 31 | + byte[] md5Bytes = md5.digest(byteArray); | ||
| 32 | + StringBuffer hexValue = new StringBuffer(); | ||
| 33 | + for (int i = 0; i < md5Bytes.length; i++) { | ||
| 34 | + int val = ((int) md5Bytes[i]) & 0xff; | ||
| 35 | + if (val < 16) { | ||
| 36 | + hexValue.append("0"); | ||
| 37 | + } | ||
| 38 | + hexValue.append(Integer.toHexString(val)); | ||
| 39 | + } | ||
| 40 | + return hexValue.toString(); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 加密解密算法 执行一次加密,两次解密 | ||
| 45 | + */ | ||
| 46 | + public static String convertMD5(String inStr) | ||
| 47 | + { | ||
| 48 | + char[] a = inStr.toCharArray(); | ||
| 49 | + for (int i = 0; i < a.length; i++) { | ||
| 50 | + a[i] = (char) (a[i] ^ 't'); | ||
| 51 | + } | ||
| 52 | + String s = new String(a); | ||
| 53 | + return s; | ||
| 54 | + } | ||
| 55 | +} |
| @@ -141,7 +141,8 @@ public class XmlUtils { | @@ -141,7 +141,8 @@ public class XmlUtils { | ||
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | // 获取密码 | 143 | // 获取密码 |
| 144 | - xmlData.setPassword(userList.get(0).getPassword()); | 144 | +// xmlData.setPassword(userList.get(0).getPassword()); |
| 145 | + | ||
| 145 | // 获取服务器ip | 146 | // 获取服务器ip |
| 146 | xmlData.setServerPort(serverList.get(0).getServerPort()); | 147 | xmlData.setServerPort(serverList.get(0).getServerPort()); |
| 147 | // 获取服务器port | 148 | // 获取服务器port |
-
请 注册 或 登录 后发表评论