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

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

thomasvargiu/rabbitmq-module
============================

Integrates php-amqplib with Zend Framework 2 and RabbitMq

5.0.0(3y ago)15143.0k—9.1%8[2 issues](https://github.com/thomasvargiu/RabbitMqModule/issues)1MITPHPPHP ^7.4 || ^8.0

Since Sep 28Pushed 3y ago2 watchersCompare

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

READMEChangelog (7)Dependencies (11)Versions (28)Used By (1)

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

[](#rabbitmqmodule)

Integrates php-amqplib with Laminas/Mezzio Framework 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' => [
        '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/thomasvargiu/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 \Laminas\ServiceManager\ServiceLocatorInterface $serviceLocator **/
$connection = $serviceLocator->get('rabbitmq.connection.default');
```

### Producers

[](#producers)

You can configure multiple producers in configuration:

```
return [
    'rabbitmq' => [
        'producer' => [
            'producer_name' => [
                'connection' => 'default', // the connection name
                'exchange' => [
                    'type' => 'direct',
                    'name' => 'exchange-name',
                    'durable' => true,      // (default)
                    'auto_delete' => false, // (default)
                    'internal' => false,    // (default)
                    'declare' => true,      // (default)
                    'arguments' => [],      // (default)
                    'ticket' => 0,          // (default)
                    'exchange_binds' => []  // (default)
                ],
                'queue' => [ // optional queue
                    'name' => 'queue-name', // can be an empty string,
                    'passive' => false,     // (default)
                    'durable' => true,      // (default)
                    'auto_delete' => false, // (default)
                    'exclusive' => 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/thomasvargiu/RabbitMqModule/blob/master/src/Options/Producer.php)
- [Exchange](https://github.com/thomasvargiu/RabbitMqModule/blob/master/src/Options/Exchange.php)
- [Queue](https://github.com/thomasvargiu/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 \Laminas\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' => [
        '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/thomasvargiu/RabbitMqModule/blob/master/src/Options/Consumer.php)
- [Exchange](https://github.com/thomasvargiu/RabbitMqModule/blob/master/src/Options/Exchange.php)
- [Queue](https://github.com/thomasvargiu/RabbitMqModule/blob/master/src/Options/Queue.php)
- [Qos](https://github.com/thomasvargiu/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 \Laminas\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' => [
        '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:fabric:setup`: Setup fabric for each service, declaring exchanges and queues
- `rabbitmq:consumers:list`: List available consumers
- `rabbitmq:consumers:start  [--without-signals|-w]`: Start a consumer by name
- `rabbitmq:rpc-server:start  [--without-signals|-w]`: Start a rpc server by name
- `rabbitmq:producer:publish  [--route=] `: Send a message with a producer

Example :

```
vendor/bin/laminas rabbitmq:producer:publish my_producer "Hello world!"
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 82.5% 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 ~133 days

Recently: every ~272 days

Total

21

Last Release

1222d ago

Major Versions

1.3.0 → 2.0.02016-10-20

2.0.2 → 3.0.0-beta2018-01-10

3.x-dev → 4.0.02020-01-21

4.0.0-beta1 → 5.0.0-beta12022-09-17

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

1.1.0PHP ^5.4 || ^7.0

1.3.0PHP ^5.5 || ^7.0

2.0.x-devPHP ^5.6 || ^7.0

3.0.0-betaPHP ^7.1

4.0.0PHP ^7.2

5.0.0-beta1PHP ^7.4 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![thomasvargiu](https://avatars.githubusercontent.com/u/732012?v=4)](https://github.com/thomasvargiu "thomasvargiu (118 commits)")[![darckking](https://avatars.githubusercontent.com/u/10863497?v=4)](https://github.com/darckking "darckking (11 commits)")[![manakao](https://avatars.githubusercontent.com/u/7046996?v=4)](https://github.com/manakao "manakao (5 commits)")[![krzysztof-gzocha](https://avatars.githubusercontent.com/u/3098559?v=4)](https://github.com/krzysztof-gzocha "krzysztof-gzocha (4 commits)")[![DannyvdSluijs](https://avatars.githubusercontent.com/u/618940?v=4)](https://github.com/DannyvdSluijs "DannyvdSluijs (2 commits)")[![bertrandgauthier](https://avatars.githubusercontent.com/u/2471512?v=4)](https://github.com/bertrandgauthier "bertrandgauthier (2 commits)")[![ildanno](https://avatars.githubusercontent.com/u/8035078?v=4)](https://github.com/ildanno "ildanno (1 commits)")

---

Tags

laminasrabbitmqmezziozf2AMQPZend Framework

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[php-amqplib/rabbitmq-bundle

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

1.3k20.1M65](/packages/php-amqplib-rabbitmq-bundle)[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2752.3M7](/packages/bschmitt-laravel-amqp)[enqueue/enqueue

Message Queue Library

19820.0M56](/packages/enqueue-enqueue)[php-amqplib/thumper

AMQP Tools

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

AMQP Tools

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

AMQP module for Zend Framework 2 to integrate RabbitMQ

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

PHPackages © 2026

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