yanglin 7 年之前
父节点
当前提交
84f5a3fafc
共有 2 个文件被更改,包括 37 次插入0 次删除
  1. 37 0
      console/controllers/RabbitUserController.php
  2. 二进制
      console/dump.rdb

+ 37 - 0
console/controllers/RabbitUserController.php

@@ -147,6 +147,43 @@ class RabbitUserController  extends Controller
         $channel->close();
         $connection->close();
     }
+
+
+
+
+    //根据消费的句柄消费后删除消息
+    public function actionAckmsg($queue='login',$msgid='13236390684',$num=1)
+    {
+
+
+        $connection = new AMQPStreamConnection(\Yii::$app->params['rabbithost'], 5673, 'guest', 'guest');
+//        $connection = new AMQPStreamConnection('172.30.118.225', 5673, 'guest', 'guest');
+        $channel = $connection->channel();
+        $channel->queue_declare($queue, false, true, false, false);
+        $callback = function ($msg) {
+            $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
+        };
+
+
+        //设置堆积数量
+        $channel->basic_qos(null, 65535, null);
+        //设置ack通知手动
+        $channel->basic_consume($queue, '', false, false, false, false, $callback);
+
+
+        //继续消费
+        while (count($channel->callbacks)) {
+            $i=0;
+            $i++;
+            if($i<$num);
+            $channel->wait();
+        }
+
+        $channel->close();
+        $connection->close();
+
+        return true;
+    }
 /*
  * demo
  *

二进制
console/dump.rdb