mirocow/yii2-queue

Yii 2.0 非阻塞队列扩展。

维护者

详细信息

github.com/Mirocow/yii2-queue

源代码

安装: 7

依赖者: 0

建议者: 2

安全: 0

星标: 10

关注者: 3

分支: 33

类型:yii2-extension

1.0.1 2018-07-10 12:00 UTC

This package is auto-updated.

Last update: 2024-09-19 09:25:42 UTC


README

Latest Stable Version Latest Unstable Version Total Downloads License Join the chat at https://gitter.im/Mirocow/yii2-queue FOSSA Status Maintainability

----------------------- YII2-QUEUE -----------------------------
Yii2-queue version: 0.0.3          PHP version:7.0.27-0+deb9u1
Process ID: 6930
Channels: 1
Workers: 4
Default queue name: default-queue
----------------------------------------------------------------
Press Ctrl+C to stop. Start success.
Child process starting with PID 6880 ...
Child process 6880 are working...
Child 6880 done
Child process starting with PID 6882 ...
Child process 6882 are working...
Run worker [web] with action [ProductCreate] from common\models\essence\Product
...
安装

php composer.phar require mirocow/yii2-queue "^1.0.0"

配置
'controllerMap' => [
    'queue' => [
        'class' => 'mirocow\queue\controllers\QueueController',
    ],
],

'components' => [

    'queue' => [
        'class' => 'mirocow\queue\components\QueueComponent',
        'queueName' => 'default-queue',
        'workers' => [
            'notification' => [
                'class' => 'mirocow\queue\components\WorkerComponent',
                'action' => [
                    'class' => 'mirocow\queue\controllers\NotificationController',
                ]
            ],
            ...
        ],
        'channels' => [
            'default' => [
                'class' => 'mirocow\queue\components\ChannelComponent',
                    'driver' => [
                        'class' => 'mirocow\queue\drivers\MysqlConnection',
                        'connection' => 'db',
                    ]
                ]
            ],
            ...
        ]
    ]
]

在使用 Mysql 驱动之前,请应用迁移

./yii migrate/up --migrationPath=@vendor/mirocow/yii2-queue/migrations

使用方法

工作类

namespace \console\controllers;

class NotificationController extends Controller
{
    public function actionSayHello($say)
    {
        \Yii::info($say);
    }
}

向队列推送消息

Yii::$app->queue->getChannel('default')->push(
    new MessageModel([
        'worker' => 'notification',
        'method' => 'actionSayHello',
        'arguments' => [
            'say' => 'hello!'
        ]
    ])
);

运行队列工作守护进程(控制台应用程序)

$ php ./yii queue/run --pid-file=/tmp/queue.pid
测试
$ ./vendor/bin/codecept -c vendor/mirocow/yii2-queue run unit

XDebug could not open the remote debug file '/var/log/php7-fpm/php-fpm-xdebug-remote'.
Codeception PHP Testing Framework v2.4.3
Powered by PHPUnit 6.5.9 by Sebastian Bergmann and contributors.

Unit Tests (6) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- ActionsTest: Run job as class methodWorker process starting with PID 23383 ...
Process 23383 are working...
Process 23383 finished
✔ ActionsTest: Run job as class method (0.15s)
- ActionsTest: Run job class static methodWorker process starting with PID 23383 ...
Process 23383 are working...
Process 23383 finished
✔ ActionsTest: Run job class static method (0.04s)
- ActionsTest: Run job as action of controllerWorker process starting with PID 23383 ...
Process 23383 are working...
Process 23383 finished
✔ ActionsTest: Run job as action of controller (0.05s)
- ActionsTest: Run job as static methodWorker process starting with PID 23383 ...
Process 23383 are working...
Process 23383 finished
✔ ActionsTest: Run job as static method (0.04s)
- FileTest: Job as class methodWorker process starting with PID 23383 ...
Process 23383 are working...
Process 23383 finished
✔ FileTest: Job as class method (0.03s)
- RedisTest: Job as classWorker process starting with PID 23383 ...
Process 23383 are working...
Process 23383 finished
✔ RedisTest: Job as class (0.03s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Time: 1.34 seconds, Memory: 16.00MB

许可证

FOSSA Status