webman/stomp队列消费者问题

kanin

问题描述

在消费者里面投递一个新的队列出现报错 Cannot declare class \Workerman\Protocols\Stomp, because the name is already in use

程序代码

消费者


use Webman\Stomp\Consumer;
use Workerman\Stomp\AckResolver;

class AsyncGeneratedVideoDataFastModel implements Consumer
{
    // 要消费的队列名
    public $queue = 'asyncGeneratedVideoDataFastModel';

    // 连接名,对应 plugin/webman/stomp/stomp.php 里的连接`
    public $connection = 'default';

    public $ack = 'client';

    // 值为 client 时需要调用$ack_resolver->ack()告诉服务端已经成功消费
    // 值为 auto   时无需调用$ack_resolver->ack()
    //public $ack = 'auto';

    // 消费
    public function consume($data, AckResolver $ack_resolver = null)
    {
        $userPlanParts = UserNovelChapterPartModel::getInstance()->getWhere(['user_planid' => $data['user_planid']])->orderBy('number', 'asc')->get();

        foreach ($userPlanParts as $val) {
         //省略多余的代码
           Common::fastModelGeneratedAIImageByTemplate($aiImageCommand, $prompt, $modelVal, $options, $source, $data['requestid'] ?? '');
        }

        //确认已经消费
        $ack_resolver->ack();
    }

    public function onConsumeFailure(\Throwable $e, $package)
    {

    }

}

Common::fastModelGeneratedAIImageByTemplate

 public static function fastModelGeneratedAIImageByTemplate($command,$prompt, $modelVal,$options=[],$source='',$sourceRequestId='')
    {

        //省略多余的代码
        // 投递消息
        RedisQueue::getInstance()->sendStompQueue($queue, $data, 'ai_image_consumer');
        //省略多余的代码
    }

RedisQueue::getInstance()->sendStompQueue


    public function sendStompQueue($queue,$data,$connect='default')
    {
        //省略多余的代码
        // 投递消息
        \Webman\Stomp\Client::connection($connect)->send($queue, json_encode($data));
    }

截图报错信息里报错文件相关代码

[2024-11-07 19:00:35] queue_exception.ERROR: 消息发送时间:  2024-11-07 19:00:35

队列ID:  65827
队列名称:  asyncGeneratedVideoDataFastModel
队列参数:  {"requestid":"289197c4ac6ae2676aabfbb1a631a330","user_planid":1780,"async_generate_prompt":1,"queueid":65827}
开始时间:  2024-11-07 19:00:33
结束时间:  2024-11-07 19:00:35
异常内容:  Cannot declare class \Workerman\Protocols\Stomp, because the name is already in use
#0 [internal function]: {closure}()
#1 /home/wwwroot/php/vendor/workerman/stomp/src/Client.php(144): class_alias()
#2 /home/wwwroot/php/vendor/webman/stomp/src/Client.php(50): Workerman\Stomp\Client->__construct()
#3 /home/wwwroot/php/vendor/webman/stomp/src/Client.php(96): Webman\Stomp\Client->__construct()
#4 /home/wwwroot/php/app/common/lib/RedisQueue.php(41): Webman\Stomp\Client::connection()
#5 /home/wwwroot/php/app/common/lib/RedisQueue.php(42): app\common\lib\RedisQueue->app\common\lib\{closure}()
#6 /home/wwwroot/php/app/common/lib/Common.php(1615): app\common\lib\RedisQueue->sendStompQueue()
#7 /home/wwwroot/php/app/queue/stomp/generatedworkfastmodel/AsyncGeneratedVideoDataFastModel.php(368): app\common\lib\Common::fastModelGeneratedAIImageByTemplate()
#8 /home/wwwroot/php/app/queue/stomp/generatedworkfastmodel/AsyncGeneratedVideoDataFastModel.php(115): app\queue\stomp\generatedworkfastmodel\AsyncGeneratedVideoDataFastModel->generatedDescAndAIImage()
#9 /home/wwwroot/php/app/queue/stomp/generatedworkfastmodel/AsyncGeneratedVideoDataFastModel.php(78): app\queue\stomp\generatedworkfastmodel\AsyncGeneratedVideoDataFastModel->handle()
#10 /home/wwwroot/php/vendor/webman/stomp/src/Process/Consumer.php(69): app\queue\stomp\generatedworkfastmodel\AsyncGeneratedVideoDataFastModel->consume()
#11 [internal function]: Webman\Stomp\Process\Consumer->Webman\Stomp\Process\{closure}()
#12 /home/wwwroot/php/vendor/workerman/stomp/src/Client.php(447): call_user_func()
#13 /home/wwwroot/php/vendor/workerman/workerman/Connection/TcpConnection.php(646): Workerman\Stomp\Client->onConnectionMessage()
#14 /home/wwwroot/php/vendor/workerman/workerman/Events/Select.php(311): Workerman\Connection\TcpConnection->baseRead()
#15 /home/wwwroot/php/vendor/workerman/workerman/Worker.php(1635): Workerman\Events\Select->loop()
#16 /home/wwwroot/php/vendor/workerman/workerman/Worker.php(1426): Workerman\Worker::forkOneWorkerForLinux()
#17 /home/wwwroot/php/vendor/workerman/workerman/Worker.php(1400): Workerman\Worker::forkWorkersForLinux()
#18 /home/wwwroot/php/vendor/workerman/workerman/Worker.php(560): Workerman\Worker::forkWorkers()
#19 /home/wwwroot/php/vendor/workerman/webman-framework/src/support/App.php(132): Workerman\Worker::runAll()
#20 /home/wwwroot/php/start.php(7): support\App::run()
#21 {main}
69 0 0
0个回答

×
🔝