PHPackages                             xutl/yii2-mq - 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. xutl/yii2-mq

ActiveYii2-extension[Queues &amp; Workers](/categories/queues)

xutl/yii2-mq
============

The message queue extension for the Yii framework

1.0.10(5y ago)181806MITPHP

Since Feb 21Pushed 5y agoCompare

[ Source](https://github.com/xutl/yii2-mq)[ Packagist](https://packagist.org/packages/xutl/yii2-mq)[ RSS](/packages/xutl-yii2-mq/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (12)Used By (0)

yii2-mq
=======

[](#yii2-mq)

适用于Yii2的消息服务组件，支持阿里云的MNS，AWS的SQS，以及Redis。

[![Latest Stable Version](https://camo.githubusercontent.com/09a2eeb7a3ff6d727c6130beb4de3974ca09e44f7b4746f87e7a58950f56b7cd/68747470733a2f2f706f7365722e707567782e6f72672f7875746c2f796969322d6d712f762f737461626c652e706e67)](https://packagist.org/packages/xutl/yii2-mq)[![Total Downloads](https://camo.githubusercontent.com/4652799558f48cd2f7b86997c829fcfa1ff5a9928041609b366431a4ad2f4f3e/68747470733a2f2f706f7365722e707567782e6f72672f7875746c2f796969322d6d712f646f776e6c6f6164732e706e67)](https://packagist.org/packages/xutl/yii2-mq)[![Reference Status](https://camo.githubusercontent.com/5eb6934564c398d944a910bcc200f206fd8ad8b8bf50b5d66288adc463f417ae/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f7875746c3a796969322d6d712f7265666572656e63655f62616467652e737667)](https://www.versioneye.com/php/xutl:yii2-mq/references)[![Build Status](https://camo.githubusercontent.com/97a4f6f05eaa5979c69cb14de60e3fa65dab9d17347ed2cef9ccbd285abc620f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7875746c2f796969322d6d712e737667)](http://travis-ci.org/xutl/yii2-mq)[![Dependency Status](https://camo.githubusercontent.com/c02b68deb9ce0f4f84b69fb1bf7b81efdf1ad7c0fd358f61699a51c57d37e859/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f7875746c3a796969322d6d712f6465762d6d61737465722f62616467652e706e67)](https://www.versioneye.com/php/xutl:yii2-mq/dev-master)[![License](https://camo.githubusercontent.com/2a3ad606380a07696e33c5a9486aed8a77c1c330ea18542e5df6a2051fdf2eb9/68747470733a2f2f706f7365722e707567782e6f72672f7875746c2f796969322d6d712f6c6963656e73652e737667)](https://packagist.org/packages/xutl/yii2-mq)

特别说明：非任务队列，也不是短消息那种私信组件，这是个纯消息组件。本来我是想做队列，我看了laravel,以及yii2其他人做的队列任务组件，我发现， 他们下发任务的时候要么发个闭包，要么发个序列化的类，包括我之前做的一个队列组件也是这么做的，后来我看了阿里云的消息队列服务的开发者 文档我觉得，消息服务本质上就是个纯消息服务，没必要把任务也放里面，一条消息就是一个普通的JSON字符串就行了，就像微信的公众号接收 服务端消息一样，接到消息干什么，怎么干我觉得是客户端的事。

\###队列说明

之前看yiisoft上那个队列半成品给我带到沟里了，且它自带的redis的一直有bug,常年不维护。

下面是队列说明：

1、插入队列的消息，可以是数组或者是json,不要直接把任务对象放入队列。 2、消费消息时，该消息只是进入了保留期，大概1分钟后又会重新进入队列。 3、如果你消费消息后，处理该消息失败，或者其他原因需要修改保留期有相应的方法修改。 4、在消息消费完，你需要手动删除该消息。

以上概念是按照 阿里云的 [https://help.aliyun.com/document\_detail/27414.html](https://help.aliyun.com/document_detail/27414.html) 实现的

知乎上这篇甩锅我给我很大的启发。

安装
--

[](#安装)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist xutl/yii2-mq

```

or add

```
"xutl/yii2-mq": "~1.0.0"

```

to the require section of your `composer.json` file.

组件配置
----

[](#组件配置)

```
//使用Redis
'queue' => [
    'class' => 'xutl\mq\redis\Client',
                'redis' => [
                    'scheme' => 'tcp',
                    'host' => '127.0.0.1',
                    'port' => 6379,
                    //'password' => '1984111a',
                    'db' => 0
                ],
],

//使用AWS SQS
'queue' => [
    'class' => 'xutl\mq\awsqs\Client',
                'sqs' => [
                    //etc
                ],
],
//使用阿里MNS
'queue' => [
   'class' => 'xutl\mq\alimns\Client',
               'endPoint' => '',
               'accessId'=>'',
               'accessKey'=>'',
],
```

使用
--

[](#使用)

```
//入队
/** @var \xutl\mq\Queue $queue */
$queue = Yii::$app->queue->getQueueRef('mailer');
for ($i = 0; $i < 500; $i++) {
    $queue->sendMessage([
        'aaa'=>'bbb',
    ]);
}

//出队
/** @var \xutl\mq\Queue $queue */
$queue = Yii::$app->queue->getQueueRef('mailer');
/** @var \xutl\mq\Message $message */
while (($message = $queue->receiveMessage()) !== false) {
    $body = $message->getBody();
    var_dump($body);
    $message->delete();
}
```

License
-------

[](#license)

This is released under the MIT License. See the bundled [LICENSE.md](LICENSE.md)for details.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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 ~148 days

Recently: every ~329 days

Total

11

Last Release

1885d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/87b658aa9d49e0c80cfc609fa2b9dc6d615672b1d895f421f751945a0e394087?d=identicon)[larvacent](/maintainers/larvacent)

---

Top Contributors

[![xutl](https://avatars.githubusercontent.com/u/20939388?v=4)](https://github.com/xutl "xutl (36 commits)")[![a7e6j2](https://avatars.githubusercontent.com/u/38258708?v=4)](https://github.com/a7e6j2 "a7e6j2 (3 commits)")[![sunmking](https://avatars.githubusercontent.com/u/33918985?v=4)](https://github.com/sunmking "sunmking (1 commits)")

---

Tags

messagephpphp7queuetaskyii2messagequeueyii2aliyun

### Embed Badge

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

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

###  Alternatives

[aliyunmq/mq-http-sdk

Aliyun Message Queue(MQ) Http PHP SDK, PHP&gt;=5.5.0

75379.9k14](/packages/aliyunmq-mq-http-sdk)[trntv/yii2-command-bus

Yii2 Command Bus extension

57625.1k8](/packages/trntv-yii2-command-bus)[bubasuma/yii2-simplechat

A simple chat for your yii2 application

889.5k](/packages/bubasuma-yii2-simplechat)[ignatenkovnikita/yii2-queuemanager

Yii2 Queue Manager

2061.8k2](/packages/ignatenkovnikita-yii2-queuemanager)

PHPackages © 2026

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