{"id":13519724,"url":"https://github.com/swarrot/swarrot","last_synced_at":"2025-05-14T07:08:26.050Z","repository":{"id":14351715,"uuid":"17061305","full_name":"swarrot/swarrot","owner":"swarrot","description":"A lib to consume message from any Broker","archived":false,"fork":false,"pushed_at":"2025-02-21T16:11:16.000Z","size":686,"stargazers_count":365,"open_issues_count":5,"forks_count":55,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-14T22:05:08.380Z","etag":null,"topics":["hacktoberfest","php","queue","queueing","rabbit","rabbitmq","swarrot"],"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-02-21T15:57:54.000Z","updated_at":"2025-02-21T16:11:21.000Z","dependencies_parsed_at":"2024-01-04T11:22:59.102Z","dependency_job_id":"bdee840c-37e5-462a-8d56-327034aa5221","html_url":"https://github.com/swarrot/swarrot","commit_stats":{"total_commits":386,"total_committers":57,"mean_commits":6.771929824561403,"dds":0.5803108808290156,"last_synced_commit":"91d2c3b76f3d8eee07f0c5bcd3ea89c2910c54ef"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarrot%2Fswarrot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarrot%2Fswarrot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarrot%2Fswarrot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarrot%2Fswarrot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swarrot","download_url":"https://codeload.github.com/swarrot/swarrot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092776,"owners_count":22013290,"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":["hacktoberfest","php","queue","queueing","rabbit","rabbitmq","swarrot"],"created_at":"2024-08-01T05:02:02.396Z","updated_at":"2025-05-14T07:08:26.029Z","avatar_url":"https://github.com/swarrot.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Swarrot\n\n[![Build Status](https://travis-ci.org/swarrot/swarrot.png)](https://travis-ci.org/swarrot/swarrot)\n[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/swarrot/swarrot/badges/quality-score.png?s=2c759b6224c762fc30a902d661b5512596060753)](https://scrutinizer-ci.com/g/swarrot/swarrot/)\n[![Latest Stable Version](https://poser.pugx.org/swarrot/swarrot/v/stable.svg)](https://packagist.org/packages/swarrot/swarrot)\n[![Latest Unstable Version](https://poser.pugx.org/swarrot/swarrot/v/unstable.svg)](https://packagist.org/packages/swarrot/swarrot)\n\nSwarrot is a PHP library to consume messages from any broker.\n\n## Installation\n\nThe recommended way to install Swarrot is through\n[Composer](http://getcomposer.org/). Require the `swarrot/swarrot` package:\n\n    $ composer require swarrot/swarrot\n\n## Usage\n\n### Basic usage\n\nFirst, you need to create a message provider to retrieve messages from your\nbroker. For example, with a `PeclPackageMessageProvider` (retrieves messages from\nan AMQP broker with the [pecl amqp package](http://pecl.php.net/package/amqp):\n\n```php\nuse Swarrot\\Broker\\MessageProvider\\PeclPackageMessageProvider;\n\n// Create connection\n$connection = new \\AMQPConnection();\n$connection-\u003econnect();\n$channel = new \\AMQPChannel($connection);\n// Get the queue to consume\n$queue = new \\AMQPQueue($channel);\n$queue-\u003esetName('global');\n\n$messageProvider = new PeclPackageMessageProvider($queue);\n```\n\nOnce it's done you need to create a `Processor` to process messages retrieved\nfrom the broker. This processor must implement\n`Swarrot\\Processor\\ProcessorInterface`. For example:\n\n```php\nuse Swarrot\\Processor\\ProcessorInterface;\nuse Swarrot\\Broker\\Message;\n\nclass Processor implements ProcessorInterface\n{\n    public function process(Message $message, array $options): bool\n    {\n        echo sprintf(\"Consume message #%d\\n\", $message-\u003egetId());\n\n        return true; // Continue processing other messages\n    }\n}\n```\n\n\nYou now have a `Swarrot\\Broker\\MessageProviderInterface` to retrieve messages\nand a Processor to process them. So, ask the `Swarrot\\Consumer` to do its job :\n\n```php\nuse Swarrot\\Consumer;\n\n$consumer = new Consumer($messageProvider, $processor);\n$consumer-\u003econsume();\n```\n\n### Using a stack\n\nHeavily inspired by [stackphp/builder](https://github.com/stackphp/builder) you\ncan use `Swarrot\\Processor\\Stack\\Builder` to stack your processors.\nUsing the [built in processors](#official-processors) or by [creating your\nown](#create-your-own-processor), you can extend the behavior of your\nbase processor.\nIn this example, your processor is decorated by 2 other processors. The\n[ExceptionCatcherProcessor](src/Swarrot/Processor/ExceptionCatcher/ExceptionCatcherProcessor.php)\nwhich decorates your own with a try/catch block and the\n[MaxMessagesProcessor](src/Swarrot/Processor/MaxMessages/MaxMessagesProcessor.php)\nwhich stops your worker when some messages have been consumed.\n\n```php\nuse Swarrot\\Processor\\ProcessorInterface;\nuse Swarrot\\Broker\\Message;\n\nclass Processor implements ProcessorInterface\n{\n    public function process(Message $message, array $options): bool\n    {\n        echo sprintf(\"Consume message #%d\\n\", $message-\u003egetId());\n        \n        return true; // Continue processing other messages\n    }\n}\n\n$stack = (new \\Swarrot\\Processor\\Stack\\Builder())\n    -\u003epush('Swarrot\\Processor\\MaxMessages\\MaxMessagesProcessor', new Logger())\n    -\u003epush('Swarrot\\Processor\\ExceptionCatcher\\ExceptionCatcherProcessor')\n    -\u003epush('Swarrot\\Processor\\Ack\\AckProcessor', $messageProvider)\n;\n\n$processor = $stack-\u003eresolve(new Processor());\n```\n\nHere is an illustration to show you what happens when this order is used:\n\n![this](https://github.com/user-attachments/assets/b1aa419d-f10a-44ef-895b-a995c3215aa6)\n\n## Processors\n\n### Official processors\n\n* [AckProcessor](src/Swarrot/Processor/Ack)\n* [Doctrine related processors](src/Swarrot/Processor/Doctrine) (thanks to [Adrien Brault](https://github.com/adrienbrault))\n* [ExceptionCatcherProcessor](src/Swarrot/Processor/ExceptionCatcher)\n* [InsomniacProcessor](src/Swarrot/Processor/Insomniac) (thanks to [Adrien Brault](https://github.com/adrienbrault))\n* [InstantRetryProcessor](src/Swarrot/Processor/InstantRetry)\n* [MaxExecutionTimeProcessor](src/Swarrot/Processor/MaxExecutionTime) (thanks to [Remy Lemeunier](https://github.com/remyLemeunier))\n* [MaxMessagesProcessor](src/Swarrot/Processor/MaxMessages) (thanks to [Remy Lemeunier](https://github.com/remyLemeunier))\n* [MemoryLimitProcessor](src/Swarrot/Processor/MemoryLimit) (thanks to [Christophe Coevoet](https://github.com/stof))\n* [RetryProcessor](src/Swarrot/Processor/Retry)\n* [ServicesResetterProcessor](src/Swarrot/Processor/ServicesResetter) (thanks to [Pierrick Vignand](https://github.com/pvgnd))\n* [SignalHandlerProcessor](src/Swarrot/Processor/SignalHandler)\n* [XDeathMaxCountProcessor](src/Swarrot/Processor/XDeath) (thanks to [Anthony Moutte](https://github.com/instabledesign))\n* [XDeathMaxLifetimeProcessor](src/Swarrot/Processor/XDeath) (thanks to [Anthony Moutte](https://github.com/instabledesign))\n\n### Create your own processor\n\nTo create your own processor and be able to use it with the `StackProcessor`, you\njust need to implement `ProcessorInterface` and to take another\n`ProcessorInterface` as first argument in constructor.\n\n## Deprecated processors \u0026 message providers / publishers\n\nIn order to reduce `swarrot/swarrot` dependencies \u0026 ease the maintenance, some\nprocessors \u0026 message providers / publishers have been deprecated in 3.x version.\nThey will be deleted in 4.0.\n\nIf you use those deprecated classes you could create your own repository to\nkeep them or we could create a dedicated repository under the swarrot\norganisation if you're willing to help to maintain them.\n\n### Message providers / publishers\n\n* SQS Message provider (in 3.5.0)\n* Stomp message providers (in 3.6.0)\n* Stomp message publishers (in 3.7.0)\n* Interop message publishers \u0026 providers (in 3.7.0)\n\n### Processors\n\n* SentryProcessor (in 3.5.0)\n* RPC related processors (in 3.5.0)\n* NewRelicProcessor (in 3.7.0)\n\n## Inspiration\n\n* [stackphp/builder](https://github.com/stackphp/builder)\n\n## License\n\nSwarrot is released under the MIT License. See the bundled LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswarrot%2Fswarrot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswarrot%2Fswarrot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswarrot%2Fswarrot/lists"}