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

ActiveSymfony-bundle[Queues &amp; Workers](/categories/queues)

swarrot/swarrot-bundle
======================

SwarrotBundle

v2.7.0(3mo ago)903.8M↓16.7%61[4 PRs](https://github.com/swarrot/SwarrotBundle/pulls)4MITPHPPHP ^8.2CI passing

Since Jun 27Pushed 3mo ago3 watchersCompare

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

READMEChangelog (10)Dependencies (16)Versions (39)Used By (4)

SwarrotBundle
=============

[](#swarrotbundle)

[![Latest Stable Version](https://camo.githubusercontent.com/bfc7ef28a326e4cec0dfbe868d225e2ba6e96e603d914f08ad27ef1d68a4d567/68747470733a2f2f706f7365722e707567782e6f72672f73776172726f742f73776172726f742d62756e646c652f762f737461626c652e706e67)](https://packagist.org/packages/swarrot/swarrot-bundle)[![Latest Unstable Version](https://camo.githubusercontent.com/b2e11f90972c1223f8d5999f00540d365fa7668dc7812f50f91bf4c2dae97ffd/68747470733a2f2f706f7365722e707567782e6f72672f73776172726f742f73776172726f742d62756e646c652f762f756e737461626c652e737667)](https://packagist.org/packages/swarrot/swarrot-bundle)

A bundle to use Swarrot inside your Symfony application.

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

[](#installation)

The recommended way to install this bundle is through [Composer](http://getcomposer.org/). Just run:

```
composer require swarrot/swarrot-bundle
```

Register the bundle in the kernel of your application:

```
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Swarrot\SwarrotBundle\SwarrotBundle(),
    );

    return $bundles;
}
```

Configuration reference
-----------------------

[](#configuration-reference)

```
swarrot:
    provider: pecl # pecl or amqp_lib (require php-amqplib/php-amqplib)
    default_connection: rabbitmq
    default_command: swarrot.command.base # Swarrot\SwarrotBundle\Command\SwarrotCommand
    logger: logger # logger or channel logger like monolog.logger.[my_channel]
    connections:
        rabbitmq:
            url: "amqp://%rabbitmq_login%:%rabbitmq_password%@%rabbitmq_host%:%rabbitmq_port%/%rabbitmq_vhost%"
    consumers:
        my_consumer:
            processor: my_consumer.processor.service # Symfony service id implementing Swarrot\Processor\ProcessorInterface
            middleware_stack: # order matters
                 - configurator: swarrot.processor.signal_handler
                   # extras:
                   #     signal_handler_signals:
                   #         - SIGTERM
                   #         - SIGINT
                   #         - SIGQUIT
                 # - configurator: swarrot.processor.insomniac
                 - configurator: swarrot.processor.max_messages
                   # extras:
                   #     max_messages: 100
                 - configurator: swarrot.processor.max_execution_time
                   # extras:
                   #     max_execution_time: 300
                 - configurator: swarrot.processor.memory_limit
                   # extras:
                   #     memory_limit: null
                 - configurator: swarrot.processor.doctrine_connection
                   # extras:
                   #     doctrine_ping: true
                   #     doctrine_close_master: true
                 - configurator: swarrot.processor.doctrine_object_manager
                 - configurator: swarrot.processor.exception_catcher

                 - configurator: swarrot.processor.ack
                   # extras:
                   #     requeue_on_error: false
                 - configurator: swarrot.processor.retry
                   # extras:
                   #     retry_exchange: retry
                   #     retry_attempts: 3
                   #     retry_routing_key_pattern: 'retry_%%attempt%%'

                 # - configurator: swarrot.processor.services_resetter

            extras:
                poll_interval: 500000
    messages_types:
        my_publisher:
            connection: rabbitmq # use the default connection by default
            exchange: my_exchange
            routing_key: my_routing_key
```

Publishing a message
--------------------

[](#publishing-a-message)

First step is to retrieve the Swarrot publisher service from your controller.

```
$messagePublisher = $this->get('swarrot.publisher');
```

After that, you need to prepare your message with the [Message](https://github.com/swarrot/swarrot/blob/master/src/Swarrot/Broker/Message.php)class.

```
use Swarrot\Broker\Message;

$message = new Message('"My first message with the awesome swarrot lib :)"');
```

Then you can publish a new message into a predefined configuration (`connection`, `exchange`, `routing_key`, etc.) from your `message_types`.

```
$messagePublisher->publish('my_publisher', $message);
```

When publishing a message, you can override the `message_types` configuration by passing a third argument:

```
$messagePublisher->publish('my_publisher', $message, array(
    'exchange'    => 'my_new_echange',
    'connection'  => 'my_second_connection',
    'routing_key' => 'my_new_routing_key'
));
```

Consuming a message
-------------------

[](#consuming-a-message)

Swarrot will automatically create one command per consumer defined in your configuration. These command need the queue name to consume as first argument. You can also use a named connection as second argument if you don't want to use the default one.

```
app/console swarrot:consume:my_consumer queue_name [connection_name]
```

Your consumer (`my_consumer.processor.service`) must implements `Swarrot\Processor\ProcessorInterface`

```
use Swarrot\Processor\ProcessorInterface;

class MyProcessor implements ProcessorInterface
{
    public function process(Message $message, array $options)
    {
        var_dump($message->getBody()); // "My first message with the awesome swarrot lib :)"
    }
}
```

Your processor will also be decorated automatically by all processors listed in the `middleware_stack` section. The order matters.

All these processors are configurable. You can add an `extras` key on each configurator definition in your `config.yml`. Take a look at [the configuration reference](#configuration-reference) to see available extras for existing Configurators.

You can also use options of the command line:

- **--poll-interval** \[default: 500000\]: Change the polling interval when no message found in broker
- **--requeue-on-error (-r)**: Re-queue the message in the same queue if an error occurred.
- **--no-catch (-C)**: Disable the ExceptionCatcher processor (available only if the processor is in the stack)
- **--max-execution-time (-t)** \[default: 300\]: Configure the MaxExecutionTime processor (available only if the processor is in the stack)
- **--max-messages (-m)** \[default: 300\]: Configure the MaxMessages processor (available only if the processor is in the stack)
- **--no-retry (-R)**: Disable the Retry processor (available only if the processor is in the stack)

Default values will be overriden by your `config.yml` and usage of options will override default config values.

Run your command with `-h` to have the full list of options.

Note that you can define one or more *aliases* for this command using the `command_alias` configuration:

```
swarrot:
    consumers:
        my_consumer:
            command_alias: 'my:super:commmand'
```

Thus allowing you to consume messages using a more appropriate wording:

```
app/console my:super:command queue_name [connection_name]
```

Implementing your own Provider
------------------------------

[](#implementing-your-own-provider)

If you want to implement your own provider (like Redis), you first have to implement the `Swarrot\SwarrotBundle\Broker\FactoryInterface`. Then, you can register it along with the others services and tag it with `swarrot.provider_factory`.

```
services:
    app.swarrot.custom_provider_factory:
        class: AppBundle\Provider\CustomFactory
        tags:
            - {name: swarrot.provider_factory}
    app.swarrot.redis_provider_factory:
        class: AppBundle\Provider\RedisFactory
        tags:
            - {name: swarrot.provider_factory, alias: redis}
```

Now you can tell Swarrot to use it in the `config.yml` file.

```
swarrot:
  provider: app.swarrot.custom_provider_factory
```

or with the alias

```
swarrot:
  provider: redis
```

Using a custom processor
------------------------

[](#using-a-custom-processor)

If you want to use a custom processor, you need two things. The `Processor`itself and a `ProcessorConfigurator`. For the `Processor`, you can refer to the [`swarrot/swarrot`documentation](https://github.com/swarrot/swarrot/#create-your-own-processor). For the `ConfigurationProcessor`, you need to implement the `ProcessorConfiguratorInterface` and to register it as an abstract service, like this:

```
services:
  my_own_processor_configurator_service_id:
    abstract: true
    class: MyProject\MyOwnProcessorConfigurator

```

Once done, just add it to the middleware stack of your consumer:

```
middleware_stack:
  - configurator: swarrot.processor.signal_handler
  - configurator: my_own_processor_configurator_service_id
```

As usual, take care of the order of your `middleware_stack`.

Running your tests without publishing
-------------------------------------

[](#running-your-tests-without-publishing)

If you use Swarrot, you may not want to actually publish messages when in test environment for example. You can use the `BlackholePublisher` to achieve this.

Simply override the `swarrot.publisher.class` parameter in the DIC with the `Swarrot\SwarrotBundle\Broker\BlackholePublisher` class, by updating `config_test.yml` for instance:

```
parameters:
    swarrot.publisher.class: Swarrot\SwarrotBundle\Broker\BlackholePublisher
```

Broker configuration
--------------------

[](#broker-configuration)

This bundle goal is to deal with message consuming, not to deal with your broker configuration. We don't want to mix the infrastructure logic with the consuming one.

If you're looking for a tool to configure your broker, take a look at [odolbeau/rabbit-mq-admin-toolkit](https://github.com/odolbeau/rabbit-mq-admin-toolkit).

License
-------

[](#license)

This bundle is released under the MIT License. See the bundled LICENSE file for details.

###  Health Score

70

—

ExcellentBetter than 100% of packages

Maintenance80

Actively maintained with recent releases

Popularity59

Moderate usage in the ecosystem

Community36

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor2

2 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 ~117 days

Recently: every ~375 days

Total

37

Last Release

105d ago

Major Versions

v1.8.1 → v2.0.02020-03-06

PHP version history (9 changes)v1.0.0PHP &gt;=5.3.3

v1.2.0PHP &gt;=5.4

v1.5.1PHP &gt;=7.1

v1.6.2PHP ^7.1

v1.7.0PHP ^7.2

v2.2.0PHP &gt;7.2.5

v2.3.0PHP &gt;=7.4

v2.4.0PHP ^7.4|^8.0

v2.7.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/75c5d927b0434111db9720dd78af8c83385cf28bb9aeafd031ba8cb0c4ffc558?d=identicon)[Stof](/maintainers/Stof)

![](https://www.gravatar.com/avatar/6662493c184b0ed32978349f4162cac376a2e1026c7f3a06cf1a9565867ecf15?d=identicon)[odolbeau](/maintainers/odolbeau)

![](https://www.gravatar.com/avatar/77cedc57ccdc487c2d60333a350b339de6bce1fc280cef3d0279a3272c1218b8?d=identicon)[olaurendeau](/maintainers/olaurendeau)

---

Top Contributors

[![odolbeau](https://avatars.githubusercontent.com/u/680206?v=4)](https://github.com/odolbeau "odolbeau (103 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (34 commits)")[![jderusse](https://avatars.githubusercontent.com/u/578547?v=4)](https://github.com/jderusse "jderusse (11 commits)")[![metfan](https://avatars.githubusercontent.com/u/1121867?v=4)](https://github.com/metfan "metfan (9 commits)")[![greg0ire](https://avatars.githubusercontent.com/u/657779?v=4)](https://github.com/greg0ire "greg0ire (7 commits)")[![pierrelemee](https://avatars.githubusercontent.com/u/7372352?v=4)](https://github.com/pierrelemee "pierrelemee (5 commits)")[![pvgnd](https://avatars.githubusercontent.com/u/5188832?v=4)](https://github.com/pvgnd "pvgnd (4 commits)")[![ThisIsAreku](https://avatars.githubusercontent.com/u/370207?v=4)](https://github.com/ThisIsAreku "ThisIsAreku (4 commits)")[![sroze](https://avatars.githubusercontent.com/u/804625?v=4)](https://github.com/sroze "sroze (4 commits)")[![lepiaf](https://avatars.githubusercontent.com/u/1940947?v=4)](https://github.com/lepiaf "lepiaf (4 commits)")[![adrienbrault](https://avatars.githubusercontent.com/u/611271?v=4)](https://github.com/adrienbrault "adrienbrault (3 commits)")[![antoox](https://avatars.githubusercontent.com/u/1968372?v=4)](https://github.com/antoox "antoox (3 commits)")[![olaurendeau](https://avatars.githubusercontent.com/u/1516110?v=4)](https://github.com/olaurendeau "olaurendeau (2 commits)")[![notFloran](https://avatars.githubusercontent.com/u/523981?v=4)](https://github.com/notFloran "notFloran (2 commits)")[![blaugueux](https://avatars.githubusercontent.com/u/767963?v=4)](https://github.com/blaugueux "blaugueux (2 commits)")[![atailouloute](https://avatars.githubusercontent.com/u/11352491?v=4)](https://github.com/atailouloute "atailouloute (2 commits)")[![Altahrim](https://avatars.githubusercontent.com/u/2705203?v=4)](https://github.com/Altahrim "Altahrim (2 commits)")[![j0k3r](https://avatars.githubusercontent.com/u/62333?v=4)](https://github.com/j0k3r "j0k3r (2 commits)")[![iamluc](https://avatars.githubusercontent.com/u/1539731?v=4)](https://github.com/iamluc "iamluc (1 commits)")[![glutamatt](https://avatars.githubusercontent.com/u/1442992?v=4)](https://github.com/glutamatt "glutamatt (1 commits)")

---

Tags

bundleconsumerphprabbitrabbitmqswarrotsymfonysymfony-bundlebundleswarrot

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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