1107012776 / easy-swoole-rabbitmq

EasySwoole 框架的 RabbitMQ 队列插件,基于 php-amqplib/php-amqplib (The RabbitMQ queue plugin for the EasySwoole framework, based on php-amqplib/php-amqplib.)
Apache License 2.0
19 stars 5 forks source link

自定义进程的时候,我在本地调试,如果电脑休眠,再次打开电脑,进程就不执行了,一直可以写入任务,但是不消费 #10

Closed prettythings closed 3 years ago

prettythings commented 3 years ago

go(function () { $MqQueue = MqQueue::getInstance()->refreshConnect(); $MqQueue->consumer()->setMoniterWaitError(function (\Exception $e){ // \EasySwoole\EasySwoole\Logger::getInstance()->log('moniterWaitErro' . var_export($e, true),\EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO,'debug');

        })->setConfig('kd_sms_send_ex','hello')->listen(function(MqJob $obj) {
            var_dump($obj->getJobData(),'receive');
            \EasySwoole\EasySwoole\Logger::getInstance()->log('receive' . var_export($obj, true),\EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO,'debug');
            return true;   //使用return true终止执行下面的代码
            //$otherMq = MqQueue::getInstance()->refreshConnect();
           // $newJob = new MqJob();
           // $newJob->setJobData('otherMq queue'.date('Y-m-d H:i:s', time()));
            //$res = $otherMq->producer()->setConfig('kd_sms_send_ex','hello_otherMq')->push($newJob);
           // var_dump($res,'send otherMq queue');
          //  \EasySwoole\EasySwoole\Logger::getInstance()->log('send otherMq queue' . var_export($newJob, true),\EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO,'debug');
           // $otherMq->closeConnection();
        });
    });
1107012776 commented 3 years ago

进程看下还在不,是否已经消亡的,可以打日志看看的,睡眠断开了的,本身消费者进程监听php-amqplib/php-amqplib会有挂起的情况,并且会自动心跳检测,保持连接,如果睡眠断网太久了,自定义进程可能就退出了,因为报错了

prettythings commented 3 years ago

我在进程里面加了定时器,定时器可以执行,但是不能消费队列了,如果重启进程后就🈶️可以了

`protected function run($arg) {

    $this->addTick(3000,function (){
       var_dump('======'.date('Y-m-d H:i:s'));
    });

    go(function () {
        $MqQueue = MqQueue::getInstance()->refreshConnect();
        $MqQueue->consumer()->setMoniterWaitError(function (\Exception $e){
            //   \EasySwoole\EasySwoole\Logger::getInstance()->log('moniterWaitErro' . var_export($e, true),\EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO,'debug');

        })->setConfig('kd_sms_send_ex','hello')->listen(function(MqJob $obj) {
            var_dump($obj->getJobData(),'receive');
            \EasySwoole\EasySwoole\Logger::getInstance()->log('receive' . var_export($obj, true),\EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO,'debug');
            return true;   //使用return true终止执行下面的代码
            //$otherMq = MqQueue::getInstance()->refreshConnect();
           // $newJob = new MqJob();
           // $newJob->setJobData('otherMq queue'.date('Y-m-d H:i:s', time()));
            //$res = $otherMq->producer()->setConfig('kd_sms_send_ex','hello_otherMq')->push($newJob);
           // var_dump($res,'send otherMq queue');
          //  \EasySwoole\EasySwoole\Logger::getInstance()->log('send otherMq queue' . var_export($newJob, true),\EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO,'debug');
           // $otherMq->closeConnection();
        });
    });
}`
1107012776 commented 3 years ago

这边使用centos系统(非本地,云服务器上面)没有发现这个问题,可能是linux系统没有休眠的这种情况 可以尝试如下: 1.禁用电脑的休眠 2.本地使用linux虚拟机

prettythings commented 3 years ago

我在看看,然后我加了 go(function () { $MqQueue = MqQueue::getInstance()->refreshConnect(); $MqQueue->consumer()->setMoniterWaitError(function (\Exception $e) { \EasySwoole\EasySwoole\Logger::getInstance()->log('moniterWaitErro' . var_export($e, true), \EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO, 'debug'); })->setConfig($exchange = 'kd_sms_send_ex', $routingKey = 'jsb_miniprogram', $mqType = 'direct', $queueName = 'jsb_miniprogram')->listen(function (MqJob $obj) { var_dump($obj->getJobData(), 'receive'); \EasySwoole\EasySwoole\Logger::getInstance()->log('receive' . var_export($obj, true), \EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO, 'debug'); return true; //使用return true终止执行下面的代码 }); });

一直提示  The connection timed out after 5 sec while awaiting incoming data'

是我配置得问题吗?
1107012776 commented 3 years ago

正常,那边的捕获moniter会有这个错误的,不用在意,这边是可以不使用setMoniterWaitError方法的 $MqQueue->consumer()->setMoniterWaitError(function (\Exception $e) { \EasySwoole\EasySwoole\Logger::getInstance()->log('moniterWaitErro' . var_export($e, true), \EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO, 'debug');


    go(function () {
        $MqQueue = MqQueue::getInstance()->refreshConnect();
        $MqQueue->consumer()->setConfig('kd_sms_send_ex','hello')->listen(function(MqJob $obj) {
            var_dump($obj->getJobData(),'receive');
            \EasySwoole\EasySwoole\Logger::getInstance()->log('receive' . var_export($obj, true),\EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO,'debug');
            return true;   //使用return true终止执行下面的代码
            //$otherMq = MqQueue::getInstance()->refreshConnect();
           // $newJob = new MqJob();
           // $newJob->setJobData('otherMq queue'.date('Y-m-d H:i:s', time()));
            //$res = $otherMq->producer()->setConfig('kd_sms_send_ex','hello_otherMq')->push($newJob);
           // var_dump($res,'send otherMq queue');
          //  \EasySwoole\EasySwoole\Logger::getInstance()->log('send otherMq queue' . var_export($newJob, true),\EasySwoole\Log\LoggerInterface::LOG_LEVEL_INFO,'debug');
           // $otherMq->closeConnection();
        });
    });
prettythings commented 3 years ago

好的,我在看看,刚换了wsl 2 顺便问下,可以批量读取队列数据么

1107012776 commented 3 years ago

不行的,目前队列只能一个一个,你可以多开几个消费者进程

prettythings commented 3 years ago

谢谢,十分感谢