{"id":14984067,"url":"https://github.com/swarrot/swarrotbundle","last_synced_at":"2026-02-02T15:17:53.767Z","repository":{"id":16275309,"uuid":"19023672","full_name":"swarrot/SwarrotBundle","owner":"swarrot","description":"A symfony bundle for swarrot integration","archived":false,"fork":false,"pushed_at":"2024-07-04T15:20:25.000Z","size":377,"stargazers_count":89,"open_issues_count":13,"forks_count":60,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T20:13:09.943Z","etag":null,"topics":["bundle","consumer","php","rabbit","rabbitmq","swarrot","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swarrot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-22T09:14:52.000Z","updated_at":"2024-07-29T08:31:18.000Z","dependencies_parsed_at":"2024-06-18T13:35:07.945Z","dependency_job_id":"e1ebe69f-58d0-40a7-91a3-f3dd4f7f83f5","html_url":"https://github.com/swarrot/SwarrotBundle","commit_stats":{"total_commits":261,"total_committers":61,"mean_commits":4.278688524590164,"dds":0.7318007662835249,"last_synced_commit":"8b69cd99b6dddd1e3ea508872d676681945665aa"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarrot%2FSwarrotBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarrot%2FSwarrotBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarrot%2FSwarrotBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarrot%2FSwarrotBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swarrot","download_url":"https://codeload.github.com/swarrot/SwarrotBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618216,"owners_count":21134199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundle","consumer","php","rabbit","rabbitmq","swarrot","symfony","symfony-bundle"],"created_at":"2024-09-24T14:08:24.028Z","updated_at":"2026-02-02T15:17:53.707Z","avatar_url":"https://github.com/swarrot.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwarrotBundle\n\n[![Latest Stable Version](https://poser.pugx.org/swarrot/swarrot-bundle/v/stable.png)](https://packagist.org/packages/swarrot/swarrot-bundle)\n[![Latest Unstable Version](https://poser.pugx.org/swarrot/swarrot-bundle/v/unstable.svg)](https://packagist.org/packages/swarrot/swarrot-bundle)\n\nA bundle to use Swarrot inside your Symfony application.\n\n## Installation\n\nThe recommended way to install this bundle is through\n[Composer](http://getcomposer.org/). Just run:\n\n```bash\ncomposer require swarrot/swarrot-bundle\n```\n\nRegister the bundle in the kernel of your application:\n\n```php\n// app/AppKernel.php\npublic function registerBundles()\n{\n    $bundles = array(\n        // ...\n        new Swarrot\\SwarrotBundle\\SwarrotBundle(),\n    );\n\n    return $bundles;\n}\n```\n\n## Configuration reference\n\n```yaml\nswarrot:\n    provider: pecl # pecl or amqp_lib (require php-amqplib/php-amqplib)\n    default_connection: rabbitmq\n    default_command: swarrot.command.base # Swarrot\\SwarrotBundle\\Command\\SwarrotCommand\n    logger: logger # logger or channel logger like monolog.logger.[my_channel]\n    connections:\n        rabbitmq:\n            url: \"amqp://%rabbitmq_login%:%rabbitmq_password%@%rabbitmq_host%:%rabbitmq_port%/%rabbitmq_vhost%\"\n    consumers:\n        my_consumer:\n            processor: my_consumer.processor.service # Symfony service id implementing Swarrot\\Processor\\ProcessorInterface\n            middleware_stack: # order matters\n                 - configurator: swarrot.processor.signal_handler\n                   # extras:\n                   #     signal_handler_signals:\n                   #         - SIGTERM\n                   #         - SIGINT\n                   #         - SIGQUIT\n                 # - configurator: swarrot.processor.insomniac\n                 - configurator: swarrot.processor.max_messages\n                   # extras:\n                   #     max_messages: 100\n                 - configurator: swarrot.processor.max_execution_time\n                   # extras:\n                   #     max_execution_time: 300\n                 - configurator: swarrot.processor.memory_limit\n                   # extras:\n                   #     memory_limit: null\n                 - configurator: swarrot.processor.doctrine_connection\n                   # extras:\n                   #     doctrine_ping: true\n                   #     doctrine_close_master: true\n                 - configurator: swarrot.processor.doctrine_object_manager\n                 - configurator: swarrot.processor.exception_catcher\n\n                 - configurator: swarrot.processor.ack\n                   # extras:\n                   #     requeue_on_error: false\n                 - configurator: swarrot.processor.retry\n                   # extras:\n                   #     retry_exchange: retry\n                   #     retry_attempts: 3\n                   #     retry_routing_key_pattern: 'retry_%%attempt%%'\n\n                 # - configurator: swarrot.processor.services_resetter\n\n            extras:\n                poll_interval: 500000\n    messages_types:\n        my_publisher:\n            connection: rabbitmq # use the default connection by default\n            exchange: my_exchange\n            routing_key: my_routing_key\n```\n\n## Publishing a message\n\nFirst step is to retrieve the Swarrot publisher service from your controller.\n\n```php\n$messagePublisher = $this-\u003eget('swarrot.publisher');\n```\n\nAfter that, you need to prepare your message with the\n[Message](https://github.com/swarrot/swarrot/blob/master/src/Swarrot/Broker/Message.php)\nclass.\n\n```php\nuse Swarrot\\Broker\\Message;\n\n$message = new Message('\"My first message with the awesome swarrot lib :)\"');\n```\n\nThen you can publish a new message into a predefined configuration\n(`connection`, `exchange`, `routing_key`, etc.) from your `message_types`.\n\n```php\n$messagePublisher-\u003epublish('my_publisher', $message);\n```\n\nWhen publishing a message, you can override the `message_types` configuration\nby passing a third argument:\n\n```php\n$messagePublisher-\u003epublish('my_publisher', $message, array(\n    'exchange'    =\u003e 'my_new_echange',\n    'connection'  =\u003e 'my_second_connection',\n    'routing_key' =\u003e 'my_new_routing_key'\n));\n```\n\n## Consuming a message\n\nSwarrot will automatically create one command per consumer defined in your\nconfiguration. These command need the queue name to consume as first argument.\nYou can also use a named connection as second argument if you don't want to use\nthe default one.\n\n```bash\napp/console swarrot:consume:my_consumer queue_name [connection_name]\n```\n\nYour consumer (```my_consumer.processor.service```) must implements ```Swarrot\\Processor\\ProcessorInterface```\n\n```php\nuse Swarrot\\Processor\\ProcessorInterface;\n\nclass MyProcessor implements ProcessorInterface\n{\n    public function process(Message $message, array $options)\n    {\n        var_dump($message-\u003egetBody()); // \"My first message with the awesome swarrot lib :)\"\n    }\n}\n```\n\nYour processor will also be decorated automatically by all processors listed in the\n`middleware_stack` section. The order matters.\n\nAll these processors are configurable.\nYou can add an `extras` key on each configurator definition in your `config.yml`.\nTake a look at [the configuration reference](#configuration-reference) to see\navailable extras for existing Configurators.\n\nYou can also use options of the command line:\n\n* **--poll-interval** [default: 500000]: Change the polling interval when no message found in broker\n* **--requeue-on-error (-r)**: Re-queue the message in the same queue if an error occurred.\n* **--no-catch (-C)**: Disable the ExceptionCatcher processor (available only if the processor is in the stack)\n* **--max-execution-time (-t)** [default: 300]: Configure the MaxExecutionTime processor (available only if the processor is in the stack)\n* **--max-messages (-m)** [default: 300]: Configure the MaxMessages processor (available only if the processor is in the stack)\n* **--no-retry (-R)**: Disable the Retry processor (available only if the processor is in the stack)\n\nDefault values will be overriden by your `config.yml` and usage of options will\noverride default config values.\n\nRun your command with `-h` to have the full list of options.\n\nNote that you can define one or more _aliases_ for this command using the `command_alias` configuration:\n\n```yaml\nswarrot:\n    consumers:\n        my_consumer:\n            command_alias: 'my:super:commmand'\n```\n\nThus allowing you to consume messages using a more appropriate wording:\n\n```bash\napp/console my:super:command queue_name [connection_name]\n```\n\n## Implementing your own Provider\n\nIf you want to implement your own provider (like Redis), you first have to\nimplement the `Swarrot\\SwarrotBundle\\Broker\\FactoryInterface`.\nThen, you can register it along with the others services and tag it with\n`swarrot.provider_factory`.\n\n```yaml\nservices:\n    app.swarrot.custom_provider_factory:\n        class: AppBundle\\Provider\\CustomFactory\n        tags:\n            - {name: swarrot.provider_factory}\n    app.swarrot.redis_provider_factory:\n        class: AppBundle\\Provider\\RedisFactory\n        tags:\n            - {name: swarrot.provider_factory, alias: redis}\n```\n\nNow you can tell Swarrot to use it in the `config.yml` file.\n\n```yaml\nswarrot:\n  provider: app.swarrot.custom_provider_factory\n```\n\nor with the alias\n\n```yaml\nswarrot:\n  provider: redis\n```\n\n## Using a custom processor\n\nIf you want to use a custom processor, you need two things. The `Processor`\nitself and a `ProcessorConfigurator`.\nFor the `Processor`, you can refer to the [`swarrot/swarrot`\ndocumentation](https://github.com/swarrot/swarrot/#create-your-own-processor).\nFor the `ConfigurationProcessor`, you need to implement the\n`ProcessorConfiguratorInterface` and to register it as an abstract service,\nlike this:\n```\nservices:\n  my_own_processor_configurator_service_id:\n    abstract: true\n    class: MyProject\\MyOwnProcessorConfigurator\n```\nOnce done, just add it to the middleware stack of your consumer:\n\n```yaml\nmiddleware_stack:\n  - configurator: swarrot.processor.signal_handler\n  - configurator: my_own_processor_configurator_service_id\n```\n\nAs usual, take care of the order of your `middleware_stack`.\n\n## Running your tests without publishing\n\nIf you use Swarrot, you may not want to actually publish messages when in test\nenvironment for example. You can use the `BlackholePublisher` to achieve this.\n\nSimply override the `swarrot.publisher.class` parameter in the DIC with the\n`Swarrot\\SwarrotBundle\\Broker\\BlackholePublisher` class, by updating\n`config_test.yml` for instance:\n\n```yaml\nparameters:\n    swarrot.publisher.class: Swarrot\\SwarrotBundle\\Broker\\BlackholePublisher\n```\n\n## Broker configuration\n\nThis bundle goal is to deal with message consuming, not to deal with your\nbroker configuration. We don't want to mix the infrastructure logic with the\nconsuming one.\n\nIf you're looking for a tool to configure your broker, take a look at\n[odolbeau/rabbit-mq-admin-toolkit](https://github.com/odolbeau/rabbit-mq-admin-toolkit).\n\n## License\n\nThis bundle is released under the MIT License. See the bundled LICENSE file for\ndetails.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswarrot%2Fswarrotbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswarrot%2Fswarrotbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswarrot%2Fswarrotbundle/lists"}