From 27fcef09b5af8d6816babf3cf063a8d62726e1d0 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期五, 19 四月 2024 09:18:01 +0800
Subject: [PATCH] 1、下片模块新增多数据源sqlserver配置 可供其他模块有需要配置的参考 2、 a、需要在各自pom文件中添加sqlserver依赖     b、在对应mapper文件中加入DS注解     c、在配置文件中配置数据源     d、主库不需要要添加DS注解指定数据库

---
 UnLoadGlassModule/src/main/java/com/mes/common/RabbitMQUtils.java |   61 ++++++++++++++++++++----------
 1 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/UnLoadGlassModule/src/main/java/com/mes/common/RabbitMQUtils.java b/UnLoadGlassModule/src/main/java/com/mes/common/RabbitMQUtils.java
index 1da8717..f381270 100644
--- a/UnLoadGlassModule/src/main/java/com/mes/common/RabbitMQUtils.java
+++ b/UnLoadGlassModule/src/main/java/com/mes/common/RabbitMQUtils.java
@@ -106,6 +106,25 @@
     }
 
 
+//鎺ユ敹闃熷垪涓墍鏈夋秷鎭紝涓嶆秷璐�
+    public static List<String> browseMessages(String queueName) throws Exception {
+        ConnectionFactory factory = new ConnectionFactory();
+        factory.setHost(host);
+        List<String> messages = new ArrayList<>();
+        try (Connection connection = factory.newConnection();
+             Channel channel = connection.createChannel()) {
+            channel.queueDeclare(queueName, false, false, false, args);
+            // 鑾峰彇闃熷垪涓殑娑堟伅
+            GetResponse response;
+            while ((response = channel.basicGet(queueName, false)) != null) {
+                String message = new String(response.getBody(), "UTF-8");
+                messages.add(message);
+            }
+        }
+        return messages;
+    }
+
+
 
     private static Set<String> sentMessageIds = new HashSet<>();
 //鏍规嵁id鍙戦�佹秷鎭�
@@ -137,32 +156,32 @@
         }
     }
 //鏍规嵁id娑堣垂娑堟伅
-    public static String consumeMessageById( String messageId,String queueName) throws Exception {
-        ConnectionFactory factory = new ConnectionFactory();
-        factory.setHost(host);
+public static String consumeMessageById(String messageId, String queueName) throws Exception {
+    ConnectionFactory factory = new ConnectionFactory();
+    factory.setHost(host);
 
-        try (Connection connection = factory.newConnection(); Channel channel = connection.createChannel()) {
-            channel.queueDeclare(queueName, false, false, false, args);
+    try (Connection connection = factory.newConnection(); Channel channel = connection.createChannel()) {
+        channel.queueDeclare(queueName, false, false, false, args);
 
-            GetResponse response;
-            while ((response = channel.basicGet(queueName, false)) != null) {
-                String receivedMessage = new String(response.getBody(), "UTF-8");
-                if (response.getProps().getMessageId().equals(messageId)) {
-                    long deliveryTag = response.getEnvelope().getDeliveryTag();
-                    channel.basicAck(deliveryTag, false);
-                    System.out.println("Selected message: "+messageId+ receivedMessage);
-                    return receivedMessage; // 杩斿洖閫夊畾鐨勬秷鎭唴瀹�
-                } else {
-                    // 瀵逛簬涓嶇鍚堟潯浠剁殑娑堟伅锛岃繘琛� Nack 鎿嶄綔
-//                    long deliveryTag = response.getEnvelope().getDeliveryTag();
-//                    channel.basicNack(deliveryTag, false, true);
-                    return "Specified message not found in the queue.";
-                }
+        GetResponse response;
+        boolean found = false;
+
+        while ((response = channel.basicGet(queueName, false)) != null) {
+            String receivedMessage = new String(response.getBody(), "UTF-8");
+            if (response.getProps().getMessageId().equals(messageId)) {
+                long deliveryTag = response.getEnvelope().getDeliveryTag();
+                channel.basicAck(deliveryTag, false);
+                System.out.println("Selected message: " + messageId + " " + receivedMessage);
+                return receivedMessage;
+            } else {
+                // 鏈壘鍒版寚瀹氭秷鎭紝缁х画鏌ユ壘
+                channel.basicReject(response.getEnvelope().getDeliveryTag(), false);
             }
-
-            return "Specified message not found in the queue.";
         }
+
+        return "Specified message not found in the queue.";
     }
+}
 
 //娑堣垂鎸囧畾娑堟伅
     public static String consumeSelectedMessage(int messageToConsume, String queueName) throws Exception {

--
Gitblit v1.8.0