{"id":18929641,"url":"https://github.com/thecodingmachine/utils.task.rabbitmq","last_synced_at":"2026-03-16T15:30:18.400Z","repository":{"id":57020169,"uuid":"60694722","full_name":"thecodingmachine/utils.task.rabbitmq","owner":"thecodingmachine","description":"Package to manage task in rabbitmq","archived":false,"fork":false,"pushed_at":"2016-06-13T16:19:21.000Z","size":18,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":8,"default_branch":"1.0","last_synced_at":"2025-02-16T12:30:31.384Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thecodingmachine.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-08T12:03:00.000Z","updated_at":"2016-06-08T12:05:49.000Z","dependencies_parsed_at":"2022-08-22T20:10:05.666Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/utils.task.rabbitmq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.task.rabbitmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.task.rabbitmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.task.rabbitmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.task.rabbitmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/utils.task.rabbitmq/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239927825,"owners_count":19719835,"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":[],"created_at":"2024-11-08T11:34:07.432Z","updated_at":"2026-03-16T15:30:18.368Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Task manage by RabbitMq\n\nThis package is used to manage task in RabbitMq.\n\n## Installation\n\n```\ncomposer require thecodingmachine/utils.task.rabbitmq\n```\n\nOnce installed, you need to register the [`TheCodingMachine\\RabbitMQServiceProvider`](src/DI/RabbitMQServiceProvider.php) into your container.\n\nIf your container supports Puli integration, you have nothing to do. Otherwise, refer to your framework or container's documentation to learn how to register *service providers*.\nFor Mouf, please see the last part.\n\n### Required\nThis package can be used without RabbitMQ, but all task are executed in real time.\nTo use RabbitMq please install it on your environment.\nAfter this add the RabbitMQ management to compute the task number in it.\n```\nrabbitmq-plugins enable rabbitmq_management\n```\n\n## Introduction\n\nThis service provider is meant to provide all the class used to create task.\n\n## Expected values / services\n\nThis *service provider* expects the following configuration / services to be available:\n\n| Name                 | Compulsory      | Type | Description                            |\n|----------------------|-----------------|------|-----------------------------|\n| `RABBITMQ_HOST`      |  **yes**    | String | The RabbitMQ host.                     |\n| `RABBITMQ_PORT`      |  **yes**    | String | The RabbitMQ user.                     |\n| `RABBITMQ_USER`      |  **yes**    | String | The RabbitMQ password.                 |\n| `RABBITMQ_PASSWORD`  |  **yes**    | String | The RabbitMQ port.                     |\n| `RABBITMQ_API_HOST`  |  **yes**    | String | The RabbitMQ management host.          |\n| `RABBITMQ_API_PORT`  |  **yes**    | String | The RabbitMQ management port.          |\n| `RABBITMQ_MAINQUEUE` |  **yes**    | String | The RabbitMQ main queue name           |\n| `RABBITMQ_ERRORQUEUE` |  *no*    | String | The RabbitMQ error queue name           |\n| `RABBITMQ_MAXPRIORITY` |  *no*    | Integer | The RabbitMQ max priority           |\n| `RABBITMQ_MAXTRIES` |  *no*    | Integer | The RabbitMQ max tries           |\n| `RABBITMQ_ENABLE` |  *no*    | Boolean | The RabbitMQ enable           |\n\nYou can edit the connection instance to add an error queue, if it's enable or not, the max tries by error and the priority.\n\n## Provided services\n\nThis *service provider* provides the following services:\n\n| Service name                                         | Description                          |\n|------------------------------------------------------|--------------------------------------|\n| `Mouf\\Utils\\Task\\Services\\RabbitMQ\\Connection`       | RabbitMQ connection   |\n| `League\\Tactician\\CommandBus`                        | Bus to manage the task type   |\n| `Mouf\\Utils\\Task\\Services\\RabbitMQ\\ConsumerService`  | Class to consum the RabbitMQ queue   |\n| `Mouf\\Utils\\Task\\Commands\\RabbitMQ\\ConsumerCommand`  | Class to add a command to consum the RabbitMQ queue   |\n| `Mouf\\Utils\\Task\\Services\\RabbitMQ\\ProducerService`  | Class to product a task in the RabbitMQ queue   |\n\n\n## Extended services\n\nThis *service provider* does not extend any service.\n\n\n## Use it\n\nYou can add an error queue if you add the errorQueue name in the \"Mouf\\Utils\\Task\\Services\\RabbitMQ\\Connection\" instance.\n\nAfter this, you can create your task. It's really simple, create a new instance with an extends to Mouf\\Utils\\Task\\Task. This class must be serialize.\nThis class is to get your information, in this example to get a carId\n```\n\u003c?php\nnamespace MyProject\\Tasks;\n\nclass GenerateCarTask extends Task\n{\n    protected $carId;\n\n    /**\n     * GenerateCarTask constructor.\n     * @param $carId\n     */\n    public function __construct($carId)\n    {\n        $this-\u003ecarId = $carId;\n    }\n\n    /**\n     * @return mixed\n     */\n    public function getCarId()\n    {\n        return $this-\u003ecarId;\n    }\n}\n```\n\nCreate the same class like Task instead of Task to Handler. Add a function handler:\n```\n\u003c?php\nnamespace MyProject\\Tasks;\n\nclass GenerateCarHandler\n{\n    /**\n     * GenerateCarHandler constructor.\n     */\n    public function __construct()\n    {\n        /* Your instance if you want */\n    }\n\n    /**\n     * @param GenerateCarTask $task\n     * @return bool\n     * @throws \\Exception\n     */\n    public function handle(GenerateCarTask $task)\n    {\n        $carId = $task-\u003egetCarId();\n\n        /* Your code */\n\n        return true;\n    }\n}\n```\n\n## Mouf installation\n\nMouf 2.0 doesn't use the provider. So you must create each instance.\nGo to the Mouf interface\nAdd the constant : \n- RABBITMQ_HOST\n- RABBITMQ_PORT\n- RABBITMQ_USER\n- RABBITMQ_PASSWORD\n- RABBITMQ_API_HOST\n- RABBITMQ_API_PORT\n- RABBITMQ_MAINQUEUE\n- RABBITMQ_ERRORQUEUE\n- RABBITMQ_MAXPRIORITY\n- RABBITMQ_MAXTRIES\n- RABBITMQ_ENABLE\n\nIn the Mouf interface, click on \"Instance\", \"Create a new instance by PHP code\" and create the followig elements:\n\n| Instance name            | Code   |\n|-----------------|------------|\n| RABBITMQ_HOST      | return RABBITMQ_HOST;  |\n| RABBITMQ_PORT       | return RABBITMQ_PORT;  |\n| RABBITMQ_USER       | return RABBITMQ_USER;  |\n| RABBITMQ_PASSWORD       | return RABBITMQ_PASSWORD;  |\n| RABBITMQ_API_HOST       | return RABBITMQ_API_HOST;  |\n| RABBITMQ_API_PORT       | return RABBITMQ_API_PORT;  |\n| RABBITMQ_MAINQUEUE       | return RABBITMQ_MAINQUEUE;  |\n| RABBITMQ_ERRORQUEUE       | return RABBITMQ_ERRORQUEUE;  |\n| RABBITMQ_MAXPRIORITY       | return RABBITMQ_MAXPRIORITY;  |\n| RABBITMQ_MAXTRIES       | return RABBITMQ_MAXTRIES;  |\n| RABBITMQ_ENABLE       | return RABBITMQ_ENABLE;  |\n| Mouf\\Utils\\Task\\Services\\RabbitMQ\\Connection       | return \\Mouf\\Utils\\Task\\DI\\RabbitMQServiceProvider::createConnection($container);  |\n| League\\Tactician\\CommandBus       | return \\Mouf\\Utils\\Task\\DI\\RabbitMQServiceProvider::createCommandBus($container);  |\n| Mouf\\Utils\\Task\\Services\\RabbitMQ\\ConsumerService       | return \\Mouf\\Utils\\Task\\DI\\RabbitMQServiceProvider::createConsumerService($container);  |\n| Mouf\\Utils\\Task\\Commands\\RabbitMQ\\ConsumerCommand       | return \\Mouf\\Utils\\Task\\DI\\RabbitMQServiceProvider::createConsumerCommand($container);  |\n| Mouf\\Utils\\Task\\Services\\RabbitMQ\\ProducerService       | return \\Mouf\\Utils\\Task\\DI\\RabbitMQServiceProvider::createProducerService($container);  |\n\nTo finish, search the \"console\" instance (class Mouf\\Console\\ConsoleApplication) and the \"Mouf\\Utils\\Task\\Commands\\RabbitMQ\\ConsumerCommand\" isntance to the \"commands\" array.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.task.rabbitmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Futils.task.rabbitmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.task.rabbitmq/lists"}