自定义进程,如何自动消费

adminadmin

一、以下书写是可以自动正常消费的

    public function onWorkerStart()
    {

        //这个在onWorkerStart里只执行一次就行了,不用放到while循环里。
        pcntl_signal(SIGINT, function () {
            Worker::stopAll();
        });

        while (true) {

               $receiptHandle = $res->getReceiptHandle();
                $res = $queue->receiveMessage(30);
                print ($res->getMessageBody());

                $delete_action = $queue->deleteMessage($receiptHandle);
                pcntl_signal_dispatch();

            } 

    }

二:以下这样书写,无法自动消费,每次restart一次就消费一次

    public function onWorkerStart()
    {

        //这个在onWorkerStart里只执行一次就行了,不用放到while循环里。
        pcntl_signal(SIGINT, function () {
            Worker::stopAll();
        });

        while (true) {

                $receiptHandle = $res->getReceiptHandle();
                $res = $queue->receiveMessage(30);
                print ($res->getMessageBody());

                //一堆事务数据库操作
                $delete_action = $queue->deleteMessage($receiptHandle);
                pcntl_signal_dispatch();

            } 

    }

三、请问是“ //一堆事务数据库操作”这部分代码导致了无法自动消费吗?应当如何修改

1380 1 1
1个回答

nitron

答案很明显:"是的"
可能原因:"一堆事务操作有错误产生"

  • 暂无评论
年代过于久远,无法发表回答
🔝