lyhzzz 1 년 전
부모
커밋
7aeb539c77
1개의 변경된 파일9개의 추가작업 그리고 2개의 파일을 삭제
  1. 9 2
      src/main/java/com/fdkankan/mqcontroller/utils/RabbitMqUtils.java

+ 9 - 2
src/main/java/com/fdkankan/mqcontroller/utils/RabbitMqUtils.java

@@ -4,6 +4,7 @@ package com.fdkankan.mqcontroller.utils;
 import cn.hutool.core.codec.Base64;
 import cn.hutool.core.util.CharsetUtil;
 import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.mqcontroller.entity.MqMsg;
 import com.fdkankan.mqcontroller.entity.MqQueueConfig;
@@ -26,19 +27,25 @@ public class RabbitMqUtils {
         log.warn("getRabbitMqMsg-url:{}",url);
         // 添加请求头
         // 设置认证信息
+        HttpResponse execute = null;
         try {
             HttpRequest request = HttpRequest.get(url)
                     .header("authorization", "Basic " +
                             Base64.encode((userName + ":" + password).getBytes(CharsetUtil.UTF_8)));
             // 发送请求,并获取响应字符串
-            String response = request.execute().body();
+            execute = request.execute();
+            String response = execute.body();
             log.warn("getRabbitMqMsg-resp:{}",response);
             JSONObject jsonObject = JSONObject.parseObject(response);
             return JSONObject.toJavaObject(jsonObject,MqMsg.class);
         }catch (Exception e){
             log.info("获取mq信息失败:",e);
+        }finally {
+            if(execute != null){
+                execute.close();
+            }
         }
-        return null;
+        return new MqMsg();
     }