{"id":20677811,"url":"https://github.com/clivern/chunk","last_synced_at":"2025-10-26T16:44:00.884Z","repository":{"id":37027700,"uuid":"247346178","full_name":"Clivern/Chunk","owner":"Clivern","description":"🐺 Asynchronous Task Queue Based on Distributed Message Passing for PHP.","archived":false,"fork":false,"pushed_at":"2025-10-09T19:14:57.000Z","size":326,"stargazers_count":37,"open_issues_count":5,"forks_count":1,"subscribers_count":0,"default_branch":"2.x","last_synced_at":"2025-10-26T15:54:43.560Z","etag":null,"topics":["async","chunk","clivern","hacktoberfest","php-async","php-sdk","queue","rabbitmq","task-queue"],"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/Clivern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"clivern"}},"created_at":"2020-03-14T20:10:58.000Z","updated_at":"2024-04-17T06:48:14.000Z","dependencies_parsed_at":"2023-12-01T18:27:45.039Z","dependency_job_id":"1bd0ab40-023b-4592-bf1e-52802ccb96a6","html_url":"https://github.com/Clivern/Chunk","commit_stats":{"total_commits":56,"total_committers":3,"mean_commits":"18.666666666666668","dds":0.2857142857142857,"last_synced_commit":"9c664cfb6f0dce8d105364494f5f63231165bb0a"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/Clivern/Chunk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FChunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FChunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FChunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FChunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clivern","download_url":"https://codeload.github.com/Clivern/Chunk/tar.gz/refs/heads/2.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FChunk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281139049,"owners_count":26450136,"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","status":"online","status_checked_at":"2025-10-26T02:00:06.575Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["async","chunk","clivern","hacktoberfest","php-async","php-sdk","queue","rabbitmq","task-queue"],"created_at":"2024-11-16T21:17:10.976Z","updated_at":"2025-10-26T16:44:00.832Z","avatar_url":"https://github.com/Clivern.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg alt=\"chunk Logo\" src=\"/assets/img/gopher.png?v=2.0.1\" width=\"180\" /\u003e\n    \u003ch3 align=\"center\"\u003eChunk\u003c/h3\u003e\n    \u003cp align=\"center\"\u003eAsynchronous Task Queue Based on Distributed Message Passing for PHP\u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n        \u003ca href=\"https://github.com/clivern/chunk/actions/workflows/php.yml\"\u003e\n            \u003cimg src=\"https://github.com/clivern/chunk/actions/workflows/php.yml/badge.svg\"\u003e\n        \u003c/a\u003e\n        \u003ca href=\"https://packagist.org/packages/clivern/chunk\"\u003e\n            \u003cimg src=\"https://img.shields.io/badge/Version-2.0.1-red.svg\"\u003e\n        \u003c/a\u003e\n        \u003ca href=\"https://github.com/Clivern/Chunk/blob/master/LICENSE\"\u003e\n            \u003cimg src=\"https://img.shields.io/badge/LICENSE-MIT-orange.svg\"\u003e\n        \u003c/a\u003e\n    \u003c/p\u003e\n\u003c/p\u003e\n\n\n## Documentation\n\n### Installation:\n\nTo install the package via `composer`, use the following:\n\n```zsh\n$ composer require clivern/chunk\n```\n\nThis command requires you to have `composer` installed globally.\n\n### Basic Usage:\n\n\nFirst create event handlers. Chunk supports these events\n- `EventInterface::ON_MESSAGE_RECEIVED_EVENT`\n- `EventInterface::ON_MESSAGE_FAILED_EVENT`\n- `EventInterface::ON_MESSAGE_HANDLED_EVENT`\n- `EventInterface::ON_MESSAGE_SENT_EVENT`\n- `EventInterface::ON_MESSAGE_SEND_FAILURE_EVENT`\n\n```php\nuse Clivern\\Chunk\\Contract\\MessageInterface;\nuse Clivern\\Chunk\\Contract\\EventInterface;\nuse Clivern\\Chunk\\Core\\EventHandler;\n\nclass MessageReceivedEvent implements EventInterface\n{\n    /**\n     * {@inheritdoc}\n     */\n    public function getType(): string\n    {\n        return EventInterface::ON_MESSAGE_RECEIVED_EVENT;\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function invoke(MessageInterface $message, $exception = null)\n    {\n        var_dump(sprintf('Message Received Event: %s', (string) $message));\n    }\n}\n\nclass MessageFailedEvent implements EventInterface\n{\n    /**\n     * {@inheritdoc}\n     */\n    public function getType(): string\n    {\n        return EventInterface::ON_MESSAGE_FAILED_EVENT;\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function invoke(MessageInterface $message, $exception = null)\n    {\n        var_dump(sprintf('Message Failed Event: %s', (string) $message));\n    }\n}\n\nclass MessageHandledEvent implements EventInterface\n{\n    /**\n     * {@inheritdoc}\n     */\n    public function getType(): string\n    {\n        return EventInterface::ON_MESSAGE_HANDLED_EVENT;\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function invoke(MessageInterface $message, $exception = null)\n    {\n        var_dump(sprintf('Message Handled Event: %s', (string) $message));\n    }\n}\n\nclass MessageSentEvent implements EventInterface\n{\n    /**\n     * {@inheritdoc}\n     */\n    public function getType(): string\n    {\n        return EventInterface::ON_MESSAGE_SENT_EVENT;\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function invoke(MessageInterface $message, $exception = null)\n    {\n        var_dump(sprintf('Message Sent Event: %s', (string) $message));\n    }\n}\n\nclass MessageSendFailureEvent implements EventInterface\n{\n    /**\n     * {@inheritdoc}\n     */\n    public function getType(): string\n    {\n        return EventInterface::ON_MESSAGE_SEND_FAILURE_EVENT;\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function invoke(MessageInterface $message, $exception = null)\n    {\n        var_dump(sprintf('Message Send Failure Event: %s', (string) $message));\n        var_dump(sprintf('Error raised: %s', $exception-\u003egetMessage()));\n    }\n}\n\n$eventHandler = new EventHandler();\n$eventHandler-\u003eaddEvent(new MessageReceivedEvent())\n             -\u003eaddEvent(new MessageFailedEvent())\n             -\u003eaddEvent(new MessageHandledEvent())\n             -\u003eaddEvent(new MessageSendFailureEvent())\n             -\u003eaddEvent(new MessageSentEvent());\n```\n\nThen create async message handlers, Each handler has a unique key so chunk can map the message to the appropriate handler.\n\nIn the following code, we create a handler to process any message with type `serviceA.processOrder`.\n\n```php\nuse Clivern\\Chunk\\Contract\\MessageHandlerInterface;\nuse Clivern\\Chunk\\Contract\\MessageInterface;\nuse Clivern\\Chunk\\Core\\Mapper;\n\nclass ProcessOrderMessageHandler implements MessageHandlerInterface\n{\n    /**\n     * Invoke Handler.\n     */\n    public function invoke(MessageInterface $message): MessageHandlerInterface\n    {\n        var_dump(sprintf('Process Message: %s', (string) $message));\n\n        return $this;\n    }\n\n    /**\n     * onSuccess Event.\n     *\n     * @return void\n     */\n    public function onSuccess()\n    {\n        var_dump('Operation Succeeded');\n    }\n\n    /**\n     * onFailure Event.\n     *\n     * @return void\n     */\n    public function onFailure()\n    {\n        var_dump('Operation Failed');\n    }\n\n    /**\n     * Handler Type.\n     */\n    public function getType(): string\n    {\n        return 'serviceA.processOrder';\n    }\n}\n\n$mapper = new Mapper();\n$mapper-\u003eaddHandler(new ProcessOrderMessageHandler());\n```\n\nThen create an instance of the message broker.\n\n```php\nuse Clivern\\Chunk\\Core\\Broker\\RabbitMQ;\n\n$broker = new RabbitMQ('127.0.0.1', 5672, 'guest', 'guest');\n```\n\n\nNow you can run listener daemon\n\n```php\nuse Clivern\\Chunk\\Core\\Listener;\n\n$listener = new Listener($broker, $eventHandler, $mapper);\n$listener-\u003econnect();\n$listener-\u003elisten();\n$listener-\u003edisconnect();\n```\n\nAnd start sending a message from a different process\n\n```php\nuse Clivern\\Chunk\\Core\\Sender;\nuse Clivern\\Chunk\\Core\\Message;\n\n$sender = new Sender($broker, $eventHandler);\n\n$sender-\u003econnect();\n\n$message = new Message();\n$message-\u003esetId(1)\n        -\u003esetUuid('f9714a92-2129-44e6-9ef4-8eebc2e33958') // or leave \u0026 chunk will generate a uuid\n        -\u003esetPayload('something')\n        -\u003esetHandlerType('serviceA.processOrder'); // same as the one defined in ProcessOrderMessageHandler class -\u003e getType method\n\n$sender-\u003esend($message);\n$sender-\u003edisconnect();\n```\n\nFor a complete working examples, please check [this folder](/examples).\n\n\n## Versioning\n\nFor transparency into our release cycle and in striving to maintain backward compatibility, Chunk is maintained under the [Semantic Versioning guidelines](https://semver.org/) and release process is predictable and business-friendly.\n\nSee the [Releases section of our GitHub project](https://github.com/clivern/chunk/releases) for changelogs for each release version of Chunk. It contains summaries of the most noteworthy changes made in each release.\n\n\n## Bug tracker\n\nIf you have any suggestions, bug reports, or annoyances please report them to our issue tracker at https://github.com/clivern/chunk/issues\n\n\n## Security Issues\n\nIf you discover a security vulnerability within Chunk, please send an email to [hello@clivern.com](mailto:hello@clivern.com)\n\n\n## Contributing\n\nWe are an open source, community-driven project so please feel free to join us. see the [contributing guidelines](CONTRIBUTING.md) for more details.\n\n\n## License\n\n© 2020, clivern. Released under [MIT License](https://opensource.org/licenses/mit-license.php).\n\n**Chunk** is authored and maintained by [@clivern](http://github.com/clivern).\n","funding_links":["https://github.com/sponsors/clivern"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclivern%2Fchunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclivern%2Fchunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclivern%2Fchunk/lists"}