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

消费进程中生产任务会出现异常 #9

Closed shuyuwang closed 2 years ago

shuyuwang commented 3 years ago

我在easyswoole 自定义进程中消费 处理结束时需要重新生产消息到另外的队列 第一次访问接口生产消息会直接报错,但实际上也入队正常执行了 只是接口响应被捕获异常然后抛出固定500错误,这是我捕获到的rabbitmq错误信息,请问这种情况怎么处理呢 /vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php:609----Framror, unexpected byte: 0

1107012776 commented 3 years ago
<?php
/**
消费者进程
**/
namespace App\Utility;

use EasySwoole\Component\Process\AbstractProcess;

use EasySwoole\RabbitMq\MqQueue;
use EasySwoole\RabbitMq\MqJob;

class MqQueueProcess extends AbstractProcess
{
    protected function run($arg)
    {
        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');

                $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

按照如上写法可以

shuyuwang commented 2 years ago

谢谢,好久没登录git了,我使用的方式和你的差不多,只不过我是把$MqQueue use进闭包中就没问题了

1107012776 commented 2 years ago

好的