Kaynağa Gözat

关闭连接

shish 8 ay önce
ebeveyn
işleme
6ef89a5f69

+ 2 - 1
common/components/rabbitmq/customConsumer.php

@@ -34,6 +34,7 @@ class customConsumer implements ConsumerInterface
                 return ConsumerInterface::MSG_REJECT;
             }
             print_r($data);
+            Yii::$app->db->open();//处理消息前确保连接可用
             // 根据操作类型分发处理
             $type = $data['type'] ?? null;
             switch ($type) {
@@ -48,7 +49,7 @@ class customConsumer implements ConsumerInterface
                     noticeUtil::push("客户的消费者报错,不存在的类型: {$type}");
                     $result = false;
             }
-
+            Yii::$app->db->close(); // 处理完后关闭连接
             if ($result) {
                 return ConsumerInterface::MSG_ACK;
             } else {

+ 1 - 1
common/components/rabbitmq/notifyConsumer.php

@@ -39,9 +39,9 @@ class notifyConsumer implements ConsumerInterface
                 return ConsumerInterface::MSG_REJECT;
             }
             print_r($data);
+            Yii::$app->db->open();//处理消息前确保连接可用
             // 根据通知类型分发处理
             $type = $data['type'] ?? null;
-            Yii::$app->db->open();//处理消息前确保连接可用
             switch ($type) {
                 case 'ghs_new_order_notify':
                     //供货商的新订单通知

+ 2 - 0
common/components/rabbitmq/stockConsumer.php

@@ -33,6 +33,7 @@ class stockConsumer implements ConsumerInterface
                 return ConsumerInterface::MSG_REJECT;
             }
             print_r($data);
+            Yii::$app->db->open();//处理消息前确保连接可用
             // 根据操作类型分发处理
             $type = $data['type'] ?? null;
             switch ($type) {
@@ -43,6 +44,7 @@ class stockConsumer implements ConsumerInterface
                     noticeUtil::push("库存的消费者报错,未知 type: {$type}");
                     $result = false;
             }
+            Yii::$app->db->close(); // 处理完后关闭连接
             if ($result) {
                 return ConsumerInterface::MSG_ACK;
             } else {