PHPackages                             m6web/amqp-bundle - 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. m6web/amqp-bundle

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

m6web/amqp-bundle
=================

Bundle AMQP

v6.0.0(2y ago)17219.3k↓55.4%18[1 issues](https://github.com/BedrockStreaming/AmqpBundle/issues)[1 PRs](https://github.com/BedrockStreaming/AmqpBundle/pulls)1PHPPHP ^8.0

Since Dec 2Pushed 2y ago43 watchersCompare

[ Source](https://github.com/BedrockStreaming/AmqpBundle)[ Packagist](https://packagist.org/packages/m6web/amqp-bundle)[ RSS](/packages/m6web-amqp-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (8)Versions (41)Used By (1)

AmQPBundle
==========

[](#amqpbundle)

[![Build Status](https://github.com/BedrockStreaming/AmqpBundle/actions/workflows/ci.yml/badge.svg)](https://github.com/BedrockStreaming/AmqpBundle/actions/workflows/ci.yml) [![Total Downloads](https://camo.githubusercontent.com/1cdfa48a6d1d2dee4258560effdb808d33086ab1210eaea8103cf33fd21204ac/68747470733a2f2f706f7365722e707567782e6f72672f6d367765622f616d71702d62756e646c652f646f776e6c6f6164732e737667)](https://packagist.org/packages/m6web/amqp-bundle) [![License](https://camo.githubusercontent.com/f50aebc0686cfbef535d23477774671778c08dffc1b8cfbaeb056ed89b89d489/687474703a2f2f706f7365722e707567782e6f72672f6d367765622f616d71702d62756e646c652f6c6963656e7365)](https://packagist.org/packages/m6web/amqp-bundle) [![PHP Version Require](https://camo.githubusercontent.com/650aa052bc279c564d634e311b3d53b4c2890821aec2ea35380529b86cb2a0bd/687474703a2f2f706f7365722e707567782e6f72672f6d367765622f616d71702d62756e646c652f726571756972652f706870)](https://packagist.org/packages/m6web/amqp-bundle)

The configuration and documentation are inspired from [videlalvaro/RabbitMqBundle](https://github.com/videlalvaro/RabbitMqBundle).

#### Amqp client as a Symfony Service

[](#amqp-client-as-a-symfony-service)

The AmqpBundle incorporates messaging in your application using the [php-amqp extension](http://pecl.php.net/package/amqp). It can communicate with any AMQP spec 0-9-1 compatible server, such as RabbitMQ, OpenAMQP and Qpid, giving you the ability to publish to any exchange and consume from any queue.

Publishing messages to AMQP Server from a Symfony controller is as easy as:

```
$msg = ["key" => "value"];
$this->myProducer->publishMessage(serialize($msg)); // where "myProducer" refers to a configured producer (see producers documentation below)
```

When you want to consume a message out of a queue:

```
$msg = $this->myConsumer->getMessage(); // where "myConsumer" refers to a configured consumer (see consumers documentation below)
```

The AmqpBundle does not provide a daemon mode to run AMQP consumers and will not. You can do it with the [M6Web/DaemonBundle](https://github.com/M6Web/DaemonBundle).

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

[](#installation)

Use composer:

```
composer require m6web/amqp-bundle
```

Then make sure the bundle is registered in your application:

```
// config/bundles.php

return [
    M6Web\Bundle\AmqpBundle\M6WebAmqpBundle::class => ['all' => true],
];
```

Usage
-----

[](#usage)

Add the `m6_web_amqp` section in your configuration file.

By default, the Symfony event dispatcher will throw an event on each command (the event contains the AMQP command and the time used to execute it). To disable this feature, as well as other events' dispatching:

```
m6_web_amqp:
   event_dispatcher: false
```

Here a configuration example:

```
m6_web_amqp:
    sandbox:
        enabled: false #optional - default false
    connections:
        default:
            host:     'localhost'  # optional - default 'localhost'
            port:     5672         # optional - default 5672
            timeout:  10           # optional - default 10 - in seconds
            login:     'guest'     # optional - default 'guest'
            password: 'guest'      # optional - default 'guest'
            vhost:    '/'          # optional - default '/'
            lazy:     false        # optional - default false
    producers:
        myproducer:
            class: "My\\Provider\\Class"                           # optional - to overload the default provider class
            connection: myconnection                               # require
            queue_options:
                name: 'my-queue'                                   # optional
                passive: bool                                      # optional - defaut false
                durable: bool                                      # optional - defaut true
                auto_delete: bool                                  # optional - defaut false
            exchange_options:
                name: 'myexchange'                                 # require
                type: direct/fanout/headers/topic                  # require
                passive: bool                                      # optional - defaut false
                durable: bool                                      # optional - defaut true
                auto_delete: bool                                  # optional - defaut false
                arguments: { key: value }                          # optional - default { } - Please refer to the documentation of your broker for information about the arguments.
                routing_keys: ['routingkey', 'routingkey2']        # optional - default { }
                publish_attributes: { key: value }                 # optional - default { } - possible keys: content_type, content_encoding, message_id, user_id, app_id, delivery_mode,
                                                                   #                          priority, timestamp, expiration, type, reply_to, headers.

    consumers:
        myconsumer:
            class: "My\\Provider\\Class"                      # optional - to overload the default consumer class
            connection: default
            exchange_options:
                name: 'myexchange'                            # require
            queue_options:
                name: 'myqueue'                               # require
                passive: bool                                 # optional - defaut false
                durable: bool                                 # optional - defaut true
                exclusive: bool                               # optional - defaut false
                auto_delete: bool                             # optional - defaut false
                arguments: { key: value }                     # optional - default { } - Please refer to the documentation of your broker for information about the arguments.
                                                              #                          RabbitMQ ex: {'x-ha-policy': 'all', 'x-dead-letter-routing-key': 'async.dead',
                                                              #                                      'x-dead-letter-exchange': 'async_dead', 'x-message-ttl': 20000}
                routing_keys: ['routingkey', 'routingkey2']   # optional - default { }
            qos_options:
                prefetch_size: integer                        # optional - default 0
                prefetch_count: integer                       # optional - default 0
```

Here we configure the connection service and the message endpoints that our application will have.

Producer and Consumer services are retrievable using `m6_web_amqp.locator` using getConsumer and getProducer.

In this example your service container will contain the services `m6_web_amqp.producer.myproducer` and `m6_web_amqp.consumer.myconsumer`.

### Producer

[](#producer)

A producer will be used to send messages to the server.

Let's say that you want to publish a message and you've already configured a producer named `myproducer` (just like above), then you'll just have to inject the `m6_web_amqp.producer.myproducer` service wherever you wan't to use it:

```
App\TheClassWhereIWantToInjectMyProducer:
    arguments: ['@m6_web_amqp.producer.myproducer']
```

```
private $myProducer;

public function __construct(\M6Web\Bundle\AmqpBundle\Amqp\Producer $myProducer) {
    $this->myProducer = $myProducer;
}

public function myFunction() {
    $msg = ["key" => "value"];
    $this->myProducer->publishMessage(serialize($msg));
}
```

**Otherwise, you could use `m6_web_amqp.locator`**

```
App\TheClassWhereIWantToRetriveMyConsumer:
    arguments: ['@m6_web_amqp.locator']
```

```
private $myProducer;

public function __construct(\M6Web\Bundle\AmqpBundle\Amqp\Locator $locator) {
    $this->locator = $locator;
}

public function myFunction() {
    $this->locator->getProducer('m6_web_amqp.produer.myproducer');
}
```

In the AMQP Model, messages are sent to an **exchange**, this means that in the configuration for a producer you will have to specify the connection options along with the `exchange_options`.

If you need to add default publishing attributes for each message, `publish_attributes` options can be something like this:

```
publish_attributes: { 'content_type': 'application/json', 'delivery_mode': 'persistent', 'priority': 8,  'expiration': '3200'}
```

If you don't want to use the configuration to define the **routing key** (for instance, if it should be computed for each message), you can define it during the call to `publishMessage()`:

```
$routingKey = $this->computeRoutingKey($message);
$this->get('m6_web_amqp.producer.myproducer')->publishMessage($message, AMQP_NOPARAM, [], [$routingKey]);
```

### Consumer

[](#consumer)

A consumer will be used to get a message from the queue.

Let's say that you want to consume a message and you've already configured a consumer named `myconsumer` (just like above), then you'll just have to inject the `m6_web_amqp.consumer.myconsumer` service wherever you wan't to use it:

```
App\TheClassWhereIWantToInjectMyConsumer:
    arguments: ['@m6_web_amqp.consumer.myconsumer']
```

```
private $myConsumer;

public function __construct(\M6Web\Bundle\AmqpBundle\Amqp\Consumer $myConsumer) {
    $this->myConsumer = $myConsumer;
}

public function myFunction() {
    $this->myConsumer->getMessage();
}
```

**Otherwise, you could use `m6_web_amqp.locator`**

```
App\TheClassWhereIWantToRetriveMyConsumer:
    arguments: ['@m6_web_amqp.locator']
```

```
private $myConsumer;

public function __construct(\M6Web\Bundle\AmqpBundle\Amqp\Locator $locator) {
    $this->locator = $locator;
}

public function myFunction() {
    $this->locator->getConsumer('m6_web_amqp.consumer.myconsumer');
}
```

The consumer does not wait for a message: getMessage will return null immediately if no message is available or return a AMQPEnvelope object if a message can be consumed. The "flags" argument of getMessage accepts AMQP\_AUTOACK (auto acknowledge by default) or AMQP\_NOPARAM (manual acknowledge).

To manually acknowledge a message, use the consumer's ackMessage/nackMessage methods with a delivery\_tag argument's value from the AMQPEnvelope object. If you choose to not acknowledge the message, the second parameter of nackMessage accepts AMQP\_REQUEUE to requeue the message or AMQP\_NOPARAM to forget it.

Be careful with qos parameters, you should know that it can hurt your performances. Please [read this](http://www.rabbitmq.com/blog/2012/05/11/some-queuing-theory-throughput-latency-and-bandwidth/). Also be aware that currently there is no `global` parameter available within PHP `amqp` extension.

### Lazy connections

[](#lazy-connections)

It's highly recommended to set all connections to `lazy: true` in the configuration file. It'll prevent the bundle from connecting to RabbitMQ on each request.

If you want lazy connections, you have to add `"ocramius/proxy-manager": "~1.0"` to your composer.json file, and (as said before) add `lazy: true` to your connections.

### DataCollector

[](#datacollector)

DataCollector is enabled by default if `kernel.debug` is `true`. Typically in the dev environment.

Docker
------

[](#docker)

If you have a multi-containers apps, we provide a Dockerfile for a container with rabbitmq-server. This container is for testing only.

Example of docker-compose.yml:

```
web:
    build: .
    volumes:
        - .:/var/www
    links:
        - rabbitmq:rabbitmq.local

rabbitmq:
    build: vendor/m6web/amqp-bundle/
    ports:
        - "15672:15672"
        - "5672:5672"

```

Testing
-------

[](#testing)

If you use this library in your application tests you will need rabbitmq instance running. If you don't want to test rabbitmq producers and consumers you can enable sandbox mode:

```
m6_web_amqp:
    sandbox:
        enabled: true
```

In this mode there will be no connection established to rabbitmq server. Producers silently accept message, consumers silently assume there are no messages available.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor5

5 contributors hold 50%+ of commits

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 ~86 days

Recently: every ~373 days

Total

40

Last Release

843d ago

Major Versions

v1.10.2 → v2.0.02016-09-29

v2.4.0 → v3.0.02017-10-19

v3.2.0 → v4.0.02022-03-09

v4.0.0 → v5.0.02023-08-08

v5.0.0 → v6.0.02024-03-12

PHP version history (4 changes)v1.0.0PHP &gt;=5.4

v3.0.0PHP ~7

v4.0.0PHP &gt;=7.4

v6.0.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2069361?v=4)[Patrick](/maintainers/Bedrock)[@Bedrock](https://github.com/Bedrock)

---

Top Contributors

[![fabdsp](https://avatars.githubusercontent.com/u/5878620?v=4)](https://github.com/fabdsp "fabdsp (16 commits)")[![omansour](https://avatars.githubusercontent.com/u/1131098?v=4)](https://github.com/omansour "omansour (13 commits)")[![thibaudgirard](https://avatars.githubusercontent.com/u/3470238?v=4)](https://github.com/thibaudgirard "thibaudgirard (11 commits)")[![Tobion](https://avatars.githubusercontent.com/u/610090?v=4)](https://github.com/Tobion "Tobion (8 commits)")[![lnahiro](https://avatars.githubusercontent.com/u/14995154?v=4)](https://github.com/lnahiro "lnahiro (6 commits)")[![magdkudama](https://avatars.githubusercontent.com/u/1323130?v=4)](https://github.com/magdkudama "magdkudama (6 commits)")[![lucascourot](https://avatars.githubusercontent.com/u/938375?v=4)](https://github.com/lucascourot "lucascourot (6 commits)")[![Oliboy50](https://avatars.githubusercontent.com/u/2571084?v=4)](https://github.com/Oliboy50 "Oliboy50 (5 commits)")[![mente](https://avatars.githubusercontent.com/u/391997?v=4)](https://github.com/mente "mente (5 commits)")[![Yokann](https://avatars.githubusercontent.com/u/5088279?v=4)](https://github.com/Yokann "Yokann (4 commits)")[![mikaelrandy](https://avatars.githubusercontent.com/u/187703?v=4)](https://github.com/mikaelrandy "mikaelrandy (4 commits)")[![jdohuutin](https://avatars.githubusercontent.com/u/1324077?v=4)](https://github.com/jdohuutin "jdohuutin (3 commits)")[![thePanz](https://avatars.githubusercontent.com/u/226021?v=4)](https://github.com/thePanz "thePanz (3 commits)")[![ChristianRiesen](https://avatars.githubusercontent.com/u/1446701?v=4)](https://github.com/ChristianRiesen "ChristianRiesen (3 commits)")[![mguillermin](https://avatars.githubusercontent.com/u/252093?v=4)](https://github.com/mguillermin "mguillermin (2 commits)")[![macintoshplus](https://avatars.githubusercontent.com/u/814683?v=4)](https://github.com/macintoshplus "macintoshplus (2 commits)")[![b-viguier](https://avatars.githubusercontent.com/u/5537799?v=4)](https://github.com/b-viguier "b-viguier (2 commits)")[![jb-reynaud](https://avatars.githubusercontent.com/u/390431?v=4)](https://github.com/jb-reynaud "jb-reynaud (2 commits)")[![lyrixx](https://avatars.githubusercontent.com/u/408368?v=4)](https://github.com/lyrixx "lyrixx (1 commits)")[![kronostof](https://avatars.githubusercontent.com/u/5948812?v=4)](https://github.com/kronostof "kronostof (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/m6web-amqp-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/m6web-amqp-bundle/health.svg)](https://phpackages.com/packages/m6web-amqp-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)[chameleon-system/chameleon-base

The Chameleon System core.

1028.6k5](/packages/chameleon-system-chameleon-base)

PHPackages © 2026

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