国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

queue redis 的 onConsumeFailure捕獲不到異常信息

wickeve

queue redis 的 onConsumeFailure捕獲不到異常信息,不多說上代碼;

<?php

namespace app\queue\redis;

use app\exceptor\custom\ParamException;
use GuzzleHttp\Exception\ServerException;
use support\Container;
use support\Log;
use Webman\RedisQueue\Consumer;

class Statistics implements Consumer
{

    // 要消費(fèi)的隊(duì)列名
    public $queue = 'statistics';
    // 連接名,對(duì)應(yīng) plugin/webman/redis-queue/redis.php 里的連接`
    public $connection = 'default';

    /**
     * @throws ParamException
     */
    public function consume($data)
    {
        echo "統(tǒng)計(jì)隊(duì)列消費(fèi)內(nèi)容\n";
        print_r($data);
        return callStatistics($data);

       /* try {
            return callStatistics($data);
        }
        catch ( \Exception $e ) {
            Log::error('statistics 統(tǒng)計(jì)隊(duì)列消費(fèi)捕獲異常',[$e->getMessage(),[$e]]);
            return $e->getMessage();
        }*/

    }

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

        echo "統(tǒng)計(jì)隊(duì)列消費(fèi)捕獲異常\n";
        echo $e->getMessage();

        // 將接收的數(shù)據(jù)寫入日志文件
        $path = runtime_path().'/logs/redisQueue/' . date('Ym');

        if (!is_dir($path)) {
            mkdir($path, 0777, true);
        }
        $path .= '/' . date('Ymd') . '.txt';

        file_put_contents($path, date('Y-m-d H:i:s')."-$this->queue" . "\n Message:".$e->getMessage() . "\n Content:" . json_encode($package,JSON_UNESCAPED_UNICODE ) . "\n\n", FILE_APPEND);

    }
}

執(zhí)行到 callStatistics 方法 ,我直接 拋出了異常, throw new ParamException('數(shù)據(jù)類型有誤');
在命令面板有拋出異常,但是我在 onConsumeFailure 下面獲取不到異常,命令面板也沒有執(zhí)行我echo 的提示 。

那位大佬遇到過這種問題,或者幫忙看看,需要怎么解決。
非常感謝。

297 2 0
2個(gè)回答

lsmir2

API
Client::__construct()
Client::send()
Client::subscribe()
Client::unsubscribe()
Client::onConsumeFailure()
onConsumeFailure 不是寫在Statistics里
我認(rèn)為應(yīng)該是什么地方發(fā)起的Client::send() 在他下方寫Client::onConsumeFailure()
要不你看下http://wtbis.cn/doc/workerman/components/workerman-redis-queue.html 這里的示例
你可以試試看,老大的例子有的時(shí)候?qū)懙木褪遣惶?xì),他可能認(rèn)為大家是跟他一個(gè)水平.

這個(gè)特性是其他開發(fā)者幾個(gè)月前提交的,如果你沒有觸發(fā)可能是版本不是最新的,把 webman/redis-queue 和 workerman/redis-queue 升級(jí)到最新試下。
下次記住有問題先升級(jí),還有提問的時(shí)候把相關(guān)組件版本號(hào)發(fā)出來。
composer info 命令能看到組件版本信息

  • wickeve 8天前

    workerman/redis v2.0.1 ;
    webman/redis-queue v1.2.4 ;
    對(duì)應(yīng)的是這兩個(gè)的版本,

  • wickeve 8天前

    搜索過問答,沒有看到相關(guān)的提問過,以為沒有出現(xiàn)過,所以就發(fā)出來咨詢一下。

??