{"id":19055999,"url":"https://github.com/open-solid/bus","last_synced_at":"2026-02-17T05:01:58.611Z","repository":{"id":205513529,"uuid":"714393278","full_name":"open-solid/bus","owner":"open-solid","description":"A message bus component for layer decoupling and separation of concerns.","archived":false,"fork":false,"pushed_at":"2024-12-13T21:16:11.000Z","size":172,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-24T04:37:52.332Z","etag":null,"topics":["cqs","message-bus","messenger","php"],"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/open-solid.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2023-11-04T19:19:36.000Z","updated_at":"2024-12-13T21:15:42.000Z","dependencies_parsed_at":"2023-11-22T04:24:02.823Z","dependency_job_id":"83580011-2f5f-47bb-90bd-971da6296a66","html_url":"https://github.com/open-solid/bus","commit_stats":null,"previous_names":["yceruto/messenger","open-solid/messenger","open-solid/bus"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/open-solid/bus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-solid%2Fbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-solid%2Fbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-solid%2Fbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-solid%2Fbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-solid","download_url":"https://codeload.github.com/open-solid/bus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-solid%2Fbus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261428234,"owners_count":23156805,"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":["cqs","message-bus","messenger","php"],"created_at":"2024-11-08T23:47:42.406Z","updated_at":"2026-01-11T09:42:42.838Z","avatar_url":"https://github.com/open-solid.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Message Bus Component\n\nA message bus component is essential in modern applications for managing communication between \ndifferent parts of the system. It acts as a central hub that routes messages between services, \nensuring decoupled and scalable architecture. This allows individual components to interact without \nneeding to know the specifics of each other, simplifying development and maintenance.\n\n## Installation\n\n```bash\ncomposer require open-solid/bus\n```\n\n## Usage\n\n### Dispatching Message with the Bus\n\nThink of the \"bus\" as a mail delivery system for your messages. It follows a \nspecific path, decided by some rules (middleware), to send your message and \nhandle it.\n\nHere's a snippet on how to set it up and dispatch a message:\n\n```php\nuse App\\Message\\MyMessage;\nuse OpenSolid\\Bus\\Handler\\MessageHandlersLocator;\nuse OpenSolid\\Bus\\Middleware\\HandlingMiddleware;\nuse OpenSolid\\Bus\\NativeMessageBus;\n\n// This is your custom function that does something when a message arrives.\n$handler = function (MyMessage $message): mixed {\n    // Do stuff with the message here...\n};\n\n// Setting up the bus with a middleware that knows who handles the message.\n$bus = new NativeMessageBus([\n    new HandlingMiddleware(new MessageHandlersLocator([\n        MyMessage::class =\u003e [$handler], // Maps messages to handlers.\n    ])),\n]);\n\n// Send a message using the bus.\n$bus-\u003edispatch(new MyMessage());\n```\n\n### Handling Messages\n\nA \"message handler\" is what does the work when a message arrives. It can be a simple \nfunction or a method in a class. Here's how you set one up:\n\n```php\nuse App\\Message\\MyMessage;\n\nclass MyMessageHandler\n{\n    public function __invoke(MyMessage $message): mixed\n    {\n        // Process the message here...\n    }\n}\n```\n\n### Middleware\n\nMiddleware are helpers that perform tasks before and after your message is handled. They \noperate at the bus level, meaning they handle all messages dispatched through the message \nbus they are linked to.\n\nHere's how to create one:\n\n```php\nuse OpenSolid\\Bus\\Envelope\\Envelope;\nuse OpenSolid\\Bus\\Middleware\\Middleware;\nuse OpenSolid\\Bus\\Middleware\\NextMiddleware;\n\nclass MyMiddleware implements Middleware\n{\n    public function handle(Envelope $envelope, NextMiddleware $next): void\n    {\n        // Do something before the message handler works.\n\n        $next-\u003ehandle($envelope); // Call the next middleware\n\n        // Do something after the message handler is done.\n    }\n}\n```\n\n### Decorators\n\nDecorators are helpers that perform tasks before and after your message is handled. Unlike\nMiddleware, decorators operate at the handler level, allowing you to modify or enhance specific \nhandlers without changing their actual code.\n\nCheck this out in [decorator](https://github.com/yceruto/decorator) and [decorator-bundle](https://github.com/yceruto/decorator-bundle) packages. \n\n## Framework Integration\n\n * [cqs-bundle](https://github.com/open-solid/cqs-bundle) - Symfony bundle for Command-Query buses.\n * [domain-event-bundle](https://github.com/open-solid/domain-event-bundle) - Symfony bundle for Event bus.\n\n## License\n\nThis tool is available under the [MIT License](LICENSE), which means you can use it pretty freely in your projects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-solid%2Fbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-solid%2Fbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-solid%2Fbus/lists"}