PHPackages                             astepin/rabbitmq-module - 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. astepin/rabbitmq-module

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

astepin/rabbitmq-module
=======================

Integrates php-amqplib with Zend Framework 3 and RabbitMq

2.0.2(8y ago)0762[1 issues](https://github.com/astepin/RabbitMqModule/issues)MITPHPPHP ^7.0

Since Sep 28Pushed 8y ago1 watchersCompare

[ Source](https://github.com/astepin/RabbitMqModule)[ Packagist](https://packagist.org/packages/astepin/rabbitmq-module)[ Docs](https://github.com/astepin/RabbitMqModule)[ RSS](/packages/astepin-rabbitmq-module/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (15)Versions (11)Used By (0)

RabbitMqModule
==============

[](#rabbitmqmodule)

[![Build Status](https://camo.githubusercontent.com/f209dce06147274da208c7fecd500a0eb882a0e4fe504d2872996c7a50b174b0/68747470733a2f2f7472617669732d63692e6f72672f6173746570696e2f5261626269744d714d6f64756c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/astepin/RabbitMqModule)[![Code Coverage](https://camo.githubusercontent.com/75a55f5d50a4e5fe4e7e01fb8ff2f4d02c6821d9d4b9ac79b758ad6f95e12441/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6173746570696e2f5261626269744d714d6f64756c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/astepin/RabbitMqModule/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/db205d13dab83e3897ade528fe8cff0304e80c4b07d7a1e269f329dd818b5b58/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6173746570696e2f5261626269744d714d6f64756c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/astepin/RabbitMqModule/?branch=master)[![Dependency Status](https://camo.githubusercontent.com/dcd2ca89ca9362286b8fc388e86f460d3380e31075ec2d1993703eb180d65a47/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537356665333434343333643138303032633139643634632f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/575fe344433d18002c19d64c)

Integrates php-amqplib with Zend Framework 3 and RabbitMq.

Inspired from [RabbitMqBundle](https://github.com/videlalvaro/RabbitMqBundle/) for Symfony 2

Usage
-----

[](#usage)

### Connections

[](#connections)

You can configure multiple connections in configuration:

```
return [
    'rabbitmq_module' => [
        'connection' => [
            // connection name
            'default' => [ // default values
                'type' => 'stream', // Available: stream, socket, ssl, lazy
                'host' => 'localhost',
                'port' => 5672,
                'username' => 'guest',
                'password' => 'guest',
                'vhost' => '/',
                'insist' => false,
                'read_write_timeout' => 2,
                'keep_alive' => false,
                'connection_timeout' => 3,
                'heartbeat' => 0
            ]
        ]
    ]
]
```

#### Option classes

[](#option-classes)

You can find all available options here:

- [Connection](https://github.com/astepin/RabbitMqModule/blob/master/src/Options/Connection.php)

#### Retrieve the service

[](#retrieve-the-service)

You can retrieve the connection from service locator:

```
// Getting the 'default' connection
/** @var \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator **/
$connection = $serviceLocator->get('rabbitmq.connection.default');
```

### Producers

[](#producers)

You can configure multiple producers in configuration:

```
return [
    'rabbitmq_module' => [
        'producer' => [
            'producer_name' => [
                'connection' => 'default', // the connection name
                'exchange' => [
                    'type' => 'direct',
                    'name' => 'exchange-name',
                    'durable' => true,      // (default)
                    'auto_delete' => false, // (default)
                    'internal' => false,    // (default)
                    'no_wait' => false,     // (default)
                    'declare' => true,      // (default)
                    'arguments' => [],      // (default)
                    'ticket' => 0,          // (default)
                    'exchange_binds' => []  // (default)
                ],
                'queue' => [ // optional queue
                    'name' => 'queue-name' // can be an empty string,
                    'type' => null,         // (default)
                    'passive' => false,     // (default)
                    'durable' => true,      // (default)
                    'auto_delete' => false, // (default)
                    'exclusive' => false,   // (default)
                    'no_wait' => false,     // (default)
                    'arguments' => [],      // (default)
                    'ticket' => 0,          // (default)
                    'routing_keys' => []    // (default)
                ],
                'auto_setup_fabric_enabled' => true // auto-setup exchanges and queues
            ]
        ]
    ]
]
```

#### Option classes

[](#option-classes-1)

You can find all available options here:

- [Producer](https://github.com/astepin/RabbitMqModule/blob/master/src/Options/Producer.php)
- [Exchange](https://github.com/astepin/RabbitMqModule/blob/master/src/Options/Exchange.php)
- [Queue](https://github.com/astepin/RabbitMqModule/blob/master/src/Options/Queue.php)

#### Retrieve the service

[](#retrieve-the-service-1)

You can retrieve the producer from service locator:

```
// Getting a producer
/** @var \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator **/
/** @var \RabbitMqModule\ProducerInterface $producer **/
$producer = $serviceLocator->get('rabbitmq.producer.producer_name');

// Sending a message
$producer->publish(json_encode(['foo' => 'bar']));
```

### Consumers

[](#consumers)

You can configure multiple consumers in configuration:

```
return [
    'rabbitmq_module' => [
        'consumer' => [
            'consumer_name' => [
                'description' => 'Consumer description',
                'connection' => 'default', // the connection name
                'exchange' => [
                    'type' => 'direct',
                    'name' => 'exchange-name'
                ],
                'queue' => [
                    'name' => 'queue-name' // can be an empty string,
                    'routing_keys' => [
                        // optional routing keys
                    ]
                ],
                'auto_setup_fabric_enabled' => true, // auto-setup exchanges and queues
                'qos' => [
                    // optional QOS options for RabbitMQ
                    'prefetch_size' => 0,
                    'prefetch_count' => 1,
                    'global' => false
                ],
                'callback' => 'my-service-name',
            ]
        ]
    ]
]
```

#### Option classes

[](#option-classes-2)

You can find all available options here:

- [Consumer](https://github.com/astepin/RabbitMqModule/blob/master/src/Options/Consumer.php)
- [Exchange](https://github.com/astepin/RabbitMqModule/blob/master/src/Options/Exchange.php)
- [Queue](https://github.com/astepin/RabbitMqModule/blob/master/src/Options/Queue.php)
- [Qos](https://github.com/astepin/RabbitMqModule/blob/master/src/Options/Qos.php)

#### Callback

[](#callback)

The `callback` key must contain one of the following:

- A `callable`: a closure or an invokable object that receive an `PhpAmqpLib\Message\AMQPMessage` object.
- An instance of `RabbitMqModule\\ConsumerInterface`.
- A string service name in service locator (can be anything `callable` or an instance of `RabbitMqModule\\ConsumerInterface`.

Take a look on `RabbitMqModule\\ConsumerInterface` class constants for available return values.

If your callback return `false` than the message will be rejected and requeued.

If your callback return anything else different from `false` and one of `ConsumerInterface`constants, the default response is like `MSG_ACK`constant.

#### Retrieve the service

[](#retrieve-the-service-2)

You can retrieve the consumer from service locator:

```
// Getting a consumer
/** @var \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator **/
/** @var \RabbitMqModule\Consumer $consumer **/
$consumer = $serviceLocator->get('rabbitmq.consumer.consumer_name');

// Start consumer
$consumer->consume();
```

There is a console command available to list and start consumers. See below.

#### Consumer Example

[](#consumer-example)

```
use PhpAmqpLib\Message\AMQPMessage;
use RabbitMqModule\ConsumerInterface;

class FetchProposalsConsumer implements ConsumerInterface
{
    /**
     * @param AMQPMessage $message
     *
     * @return int
     */
    public function execute(AMQPMessage $message)
    {
        $data = json_decode($message->body, true);

        try {
            // do something...
        } catch (\PDOException $e) {
            return ConsumerInterface::MSG_REJECT_REQUEUE;
        } catch (\Exception $e) {
            return ConsumerInterface::MSG_REJECT;
        }

        return ConsumerInterface::MSG_ACK;
    }
}
```

Exchange2exchange binding
-------------------------

[](#exchange2exchange-binding)

You can configure exchange2exchange binding in producers or consumers. Example:

```
return [
    'rabbitmq_module' => [
        'consumer' => [
            'consumer_name' => [
                // ...
                'exchange' => [
                    'type' => 'fanout',
                    'name' => 'exchange_to_bind_to',
                    'exchange_binds' => [
                        [
                            'exchange' => [
                                'type' => 'fanout',
                                'name' => 'main_exchange'
                            ],
                            'routing_keys' => [
                                '#'
                            ]
                        ]
                    ]
                ],
            ]
        ]
    ]
]
```

Console usage
-------------

[](#console-usage)

There are some console commands available:

- `rabbitmq-module setup-fabric`: Setup fabric for each service, declaring exchanges and queues
- `rabbitmq-module list consumers`: List available consumers
- `rabbitmq-module consumer  [--without-signals|-w]`: Start a consumer by name
- `rabbitmq-module rpc_server  [--without-signals|-w]`: Start a rpc server by name
- `rabbitmq-module stdin-producer  [--route=] `: Send a message with a producer

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 63.2% 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 ~84 days

Recently: every ~139 days

Total

10

Last Release

3169d ago

Major Versions

1.0.2 → 2.0.0.x-dev2016-02-19

1.2.1 → 2.0.02016-06-29

PHP version history (5 changes)1.0.0PHP &gt;=5.4.0

2.0.0.x-devPHP &gt;=5.5.0

1.1.0PHP ^5.4 || ^7.0

2.0.0PHP ^5.6 || ^7.0

2.0.2PHP ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/297617?v=4)[Artem Stepin](/maintainers/astepin)[@astepin](https://github.com/astepin)

---

Top Contributors

[![thomasvargiu](https://avatars.githubusercontent.com/u/732012?v=4)](https://github.com/thomasvargiu "thomasvargiu (55 commits)")[![astepin](https://avatars.githubusercontent.com/u/297617?v=4)](https://github.com/astepin "astepin (23 commits)")[![fntlnz](https://avatars.githubusercontent.com/u/3083633?v=4)](https://github.com/fntlnz "fntlnz (5 commits)")[![krzysztof-gzocha](https://avatars.githubusercontent.com/u/3098559?v=4)](https://github.com/krzysztof-gzocha "krzysztof-gzocha (4 commits)")

---

Tags

phprabbitmqzendzend-frameworkzendframeworkrabbitmqzf2AMQPZend Frameworkzf3zend module

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/astepin-rabbitmq-module/health.svg)

```
[![Health](https://phpackages.com/badges/astepin-rabbitmq-module/health.svg)](https://phpackages.com/packages/astepin-rabbitmq-module)
```

###  Alternatives

[php-amqplib/rabbitmq-bundle

Integrates php-amqplib with Symfony &amp; RabbitMq. Formerly emag-tech-labs/rabbitmq-bundle, oldsound/rabbitmq-bundle.

1.2k20.7M68](/packages/php-amqplib-rabbitmq-bundle)[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2792.4M7](/packages/bschmitt-laravel-amqp)[thomasvargiu/rabbitmq-module

Integrates php-amqplib with Zend Framework 2 and RabbitMq

15157.5k1](/packages/thomasvargiu-rabbitmq-module)[php-amqplib/thumper

AMQP Tools

276211.9k8](/packages/php-amqplib-thumper)[videlalvaro/thumper

AMQP Tools

27683.4k3](/packages/videlalvaro-thumper)[prolic/humus-amqp-module

AMQP module for Zend Framework 2 to integrate RabbitMQ

3057.0k1](/packages/prolic-humus-amqp-module)

PHPackages © 2026

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