From 09fe50d59e2f1e2261d376eb49ad6c40301f25b4 Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期五, 10 五月 2024 16:08:59 +0800
Subject: [PATCH] 修改IP与数据库连接

---
 springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java b/springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java
index 3d8d51c..2745f5e 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java
@@ -3,6 +3,9 @@
 import com.rabbitmq.client.*;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class RabbitMQUtils {
     // ObjectMapper瀵硅薄锛岀敤浜庡簭鍒楀寲鍜屽弽搴忓垪鍖朖SON
     private static ObjectMapper objectMapper = new ObjectMapper();
@@ -25,6 +28,28 @@
         }
     }
 
+
+    public List<String> readMessages(String queueName) throws Exception {
+        ConnectionFactory factory = new ConnectionFactory();
+        factory.setHost("localhost");
+        List<String> messages = new ArrayList<>();
+        try (Connection connection = factory.newConnection();
+             Channel channel = connection.createChannel()) {
+            boolean autoAck = false;
+
+            GetResponse response = channel.basicGet(queueName, autoAck);
+            if (response != null) {
+                String message = new String(response.getBody(), "UTF-8");
+                messages.add(message);
+                // 鎵嬪姩纭娑堟伅澶勭悊瀹屾垚
+                long deliveryTag = response.getEnvelope().getDeliveryTag();
+                channel.basicAck(deliveryTag, false);
+            }
+        }
+
+        return messages;
+    }
+
     // 浠� RabbitMQ 闃熷垪涓帴鏀舵秷鎭�
     public static void receiveMessage(String queueName) throws Exception {
         // 鍒涘缓杩炴帴宸ュ巶骞惰缃富鏈哄悕

--
Gitblit v1.8.0