Closed shuyuwang closed 2 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();
});
});
}
}
按照如上写法可以
谢谢,好久没登录git了,我使用的方式和你的差不多,只不过我是把$MqQueue use进闭包中就没问题了
好的
我在easyswoole 自定义进程中消费 处理结束时需要重新生产消息到另外的队列 第一次访问接口生产消息会直接报错,但实际上也入队正常执行了 只是接口响应被捕获异常然后抛出固定500错误,这是我捕获到的rabbitmq错误信息,请问这种情况怎么处理呢 /vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php:609----Framror, unexpected byte: 0