PHPackages                             albertwill/yii2-rabbitmq - 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. albertwill/yii2-rabbitmq

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

albertwill/yii2-rabbitmq
========================

Maintained fork of mikemadisonweb/yii2-rabbitmq that fixes duplicate multi-connection registration issues and improves worker process robustness.

v2.9.3(5mo ago)0120↑77.8%MITPHPPHP &gt;=7.1

Since Dec 23Pushed 5mo agoCompare

[ Source](https://github.com/AlbertWill/yii2-rabbitmq)[ Packagist](https://packagist.org/packages/albertwill/yii2-rabbitmq)[ RSS](/packages/albertwill-yii2-rabbitmq/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

RabbitMQ Extension for Yii2
===========================

[](#rabbitmq-extension-for-yii2)

Wrapper based on php-amqplib library to incorporate messaging in your Yii2 application via RabbitMQ. Inspired by RabbitMqBundle for Symfony framework.

**Note**: This is a fork of [mikemadisonweb/yii2-rabbitmq](https://github.com/mikemadisonweb/yii2-rabbitmq) with the following enhancements:

- **Multi-connection isolation**: Each connection independently manages its queues, exchanges, and bindings
- **Automatic reconnection**: Consumer and Producer automatically handle connection failures and reconnect
- **Semaphore support**: Control concurrent consumer instances in Kubernetes auto-scaling scenarios

This documentation is relevant for the version 2.\*, which require PHP version &gt;=7.0. For legacy PHP applications &gt;=5.4 please use [previous version of this extension](https://github.com/mikemadisonweb/yii2-rabbitmq/blob/master/README_v1.md).

[![Latest Stable Version](https://camo.githubusercontent.com/dd234fc4b3144917188273390ba18edc56d54609045e7f5d73175850a888daa2/68747470733a2f2f706f7365722e707567782e6f72672f616c6265727477696c6c2f796969322d7261626269746d712f762f737461626c65)](https://packagist.org/packages/albertwill/yii2-rabbitmq)[![License](https://camo.githubusercontent.com/c960b58828c1772e257a1a18a06be6745f0ed035fccf37d430f30581245ee703/68747470733a2f2f706f7365722e707567782e6f72672f616c6265727477696c6c2f796969322d7261626269746d712f6c6963656e7365)](https://packagist.org/packages/albertwill/yii2-rabbitmq)[![Build Status](https://camo.githubusercontent.com/9b63e40514a6f97cde14e724d89ff428829d80fca58ae31ea8a19124ef402320/68747470733a2f2f7472617669732d63692e6f72672f616c6265727477696c6c2f796969322d7261626269746d712e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/albertwill/yii2-rabbitmq)[![Coverage Status](https://camo.githubusercontent.com/2b6e3c81fdf2f0f95699aad8c74b6a965cdd002a71c4b91296a02ebf6edc449c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f616c6265727477696c6c2f796969322d7261626269746d712f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/albertwill/yii2-rabbitmq?branch=master)[![FOSSA Status](https://camo.githubusercontent.com/3afc32fbb236d954fdfb8c864b45e842a7299cb24114ebf70bf84e049327d8a2/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246616c6265727477696c6c253246796969322d7261626269746d712e7376673f747970653d736869656c64)](https://app.fossa.io/projects/git%2Bgithub.com%2Falbertwill%2Fyii2-rabbitmq?ref=badge_shield)

Installation
------------

[](#installation)

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

Either run

```
php composer.phar require albertwill/yii2-rabbitmq

```

or add

```
"albertwill/yii2-rabbitmq": "^2.8"
```

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

Configuration
-------------

[](#configuration)

This extension facilitates the creation of RabbitMQ [producers and consumers](https://www.rabbitmq.com/tutorials/tutorial-three-php.html) to meet your specific needs.

**Note**: If you plan to use Semaphore feature, you need to configure both Redis component and application ID:

**Required Configuration for Semaphore:**

The `Yii::$app->id` is used to generate unique semaphore keys to avoid conflicts between different projects sharing the same Redis instance. Both Redis component and `Yii::$app->id` are required for Semaphore feature.

```
// config/web.php or config/console.php
return [
    'id' => 'my_app_id',  // Required for Semaphore feature
    'name' => 'My Application',

    'components' => [
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 0,
            // 'password' => 'your_password',  // if needed
        ],
        // ... other components ...
    ],
    // ... other config ...
];
```

**Important**: If `Yii::$app->id` is not set or empty, the Semaphore feature will throw an `InvalidConfigException`. The semaphore key is automatically generated as: `rabbitmq:semaphore:{app_id}:{consumer_name}` to ensure uniqueness across different projects and consumers.

This is an example basic config:

```
