PHPackages                             alan/yii2-mq-task - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. alan/yii2-mq-task

ActiveLibrary[Queues &amp; Workers](/categories/queues)

alan/yii2-mq-task
=================

yii2 framework mq task v2.0

v3.0.4(3y ago)025PHPCI failing

Since Dec 19Pushed 3y ago1 watchersCompare

[ Source](https://github.com/wzzjjboy/yii2-mq-task)[ Packagist](https://packagist.org/packages/alan/yii2-mq-task)[ RSS](/packages/alan-yii2-mq-task/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (7)Versions (13)Used By (0)

Yii2 MQ TASK
============

[](#yii2-mq-task)

1. 特性
2. 安装

    composer require alan/yii2-mq-task:dev-master
3. 配置

    > 1.0.x有消费者卡死的Bug, 解决的办法是升级了swoole到4.5.\*的版本，使用Pool代替原来的swoole\_service。
    >
    > 关于1.0.0升级到2.0的配置的变更，由于2.x采用Yii2框架自身的日志组件又要在消费任务的时候刷新LogId, 所以需要替换文件类，配置层级 composents =&gt; logs =&gt; targets =&gt; class: yii2\\mq\_task\\components\\FileTarget

    - 添加配置

        ```
        'db' => [ //默认db配置
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=host;port=port;dbname=dbname',
            'username' => 'username',
            'password' => 'password',
            'charset' => 'utf8',
            'tablePrefix' => 'tablePrefix',
            'commandClass' => 'yii2\mq_task\components\DbCommand',
         ],
        'redis' => [	//redis配置
            'class' => 'yii2\mq_task\components\RedisConnection',
            'hostname' => 'hostname',
            'port' => 'port',
            'database' => 1,
            'password' => 'password'
        ],
        'invoiceRedisEvent' => [ //mq_task的名字
            'class'         => 'console\mqTask\InvoiceRedisEvent',
            'host'          => 'host',
            'port'          => 'port',
            'username'      => 'username',
            'password'      => 'password',
            'exchange_name' => 'exchange_name',
            'queue_name'    => 'queue_name',
            'routing_key'   => 'routing_key',
        ],
        'messageQueue'      => [
                'class'     => 'yii2\mq_task\basic\MQEngine',
        		 'processNamePrefix' => "cloudMq",
                'log'       		=> [
                    'class'    	=> 'yii2\mq_task\basic\Log',
                    'category'  => 'mq_task',
                ],
                'tasks'     => [
                    'invoiceRedisEvent' => 5, //要处理的mq_task和对应的进程数
                ]
        ],
        'request' => [
          	'as beforeAction' => [
            	'class' => \yii2\mq_task\components\LogIDBehavior::class, //替换
            	'name'  => 'console',
          ]
        ],
        //替换console的日志类
        'components' => [
        	'log' => [
            	[
                'class' => 'yii2\mq_task\components\FileTarget', //替换
                'levels' => ['warning', 'info','error'],
                'categories' =>['server'],
                'exportInterval' => 1, //这里注重，太大日志则不能及时刷入文件，太小会影响性能
                'logVars' => [],
                'logFile' => __DIR__ . '/../runtime/logs/server_'. date("ymd") .'.log',
                'maxFileSize' => 1024 * 1024,//日志大小1G，以kb为单位的
                'maxLogFiles'=>5
              ],
          ],
        ]
        ```
    - 添加启动脚本

    ```
    namespace console\controllers;

    use Yii;
    use yii\console\Controller;
    use yii2\mq_task\basic\MQEngine;

    class MqController extends Controller
    {
        /**
         * @return MQEngine
         * @throws \yii\base\InvalidConfigException
         */
        public function getMQ(){
            return Yii::$app->get("messageQueue");
     }

     /**
         * 启动MQ
         */
        public function actionStart()
        {
            $this->getMQ()->start();
        }

        /**
         * 停止MQ
         */
        public function actionStop()
        {

            $this->getMQ()->stop();
        }

        /**
         * MQ状态查询
         */
        public function actionStatus()
        {
            $this->getMQ()->status();
        }

        /**
         * 服务热重启
         */
        public function actionReload()
        {
            $this->getMQ()->reload();
        }

        /**
         * 重启服务
         */
        public function actionRestart()
        {
            $this->getMQ()->restart();
        }
    }
    ```

    - 启动

        ```
        php yii mq/start
        ```
    - 停止

        ```
        php yii mq/stop
        ```
    - 热重启

        ```
         ```php
         php yii mq/reload
         ```

        ```
    - 重启
        `php php yii mq/restart `
    - 查看状态
        `php php yii mq/status `
    - 书写任务消费类

        ```
        namespace console\mqTask;

        use yii2\mq_task\basic\Task;

        class InvoiceRedisEvent extends Task {

            /**
             * @param array $data
             * @return bool
             */
            public function consume(array $data): bool {
                // TODO: Implement consume() method.
                print_r($data);//在这里处理任务
                return true;
            }
        }
        ```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~102 days

Recently: every ~37 days

Total

11

Last Release

1308d ago

Major Versions

v1.0.3 → 2.0.02021-11-17

v2.0.3 → v3.0.12022-05-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/c0834b401e5bb45e8f76303cd0284840de2a2c5f1c6443857174b81cf111666e?d=identicon)[wzzjjboy](/maintainers/wzzjjboy)

---

Top Contributors

[![lzcmaro](https://avatars.githubusercontent.com/u/15357931?v=4)](https://github.com/lzcmaro "lzcmaro (7 commits)")[![wzzjjboy](https://avatars.githubusercontent.com/u/13265064?v=4)](https://github.com/wzzjjboy "wzzjjboy (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alan-yii2-mq-task/health.svg)

```
[![Health](https://phpackages.com/badges/alan-yii2-mq-task/health.svg)](https://phpackages.com/packages/alan-yii2-mq-task)
```

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

53541.0k3](/packages/jolicode-castor)[toin0u/geotools

Geo-related tools PHP 7.3+ library

1.4k1.3k](/packages/toin0u-geotools)[riki137/multitron

Tool for managing fast both asynchronous and multi-threaded execution of tasks. Focused on performance and pleasant CLI interface.

9016.8k](/packages/riki137-multitron)[ecotone/symfony-bundle

Extends Ecotone with Symfony integration

11229.0k1](/packages/ecotone-symfony-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
