{"id":24624852,"url":"https://github.com/agencypmg/queue-tactician","last_synced_at":"2025-05-07T17:11:34.661Z","repository":{"id":57043071,"uuid":"41444797","full_name":"AgencyPMG/queue-tactician","owner":"AgencyPMG","description":"Integrate the wonderful Tactician library with pmg/queue.","archived":false,"fork":false,"pushed_at":"2024-04-09T23:36:41.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-01-18T12:07:03.809Z","etag":null,"topics":["command-bus","php","pmg-queue","pmg-queue-driver","queue","tactician"],"latest_commit_sha":null,"homepage":"http://pmg-queue.readthedocs.io/en/latest/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AgencyPMG.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}},"created_at":"2015-08-26T19:11:10.000Z","updated_at":"2021-10-15T02:06:41.000Z","dependencies_parsed_at":"2024-04-09T22:24:42.800Z","dependency_job_id":null,"html_url":"https://github.com/AgencyPMG/queue-tactician","commit_stats":{"total_commits":25,"total_committers":4,"mean_commits":6.25,"dds":0.28,"last_synced_commit":"bd4cbcf2a6342c18e268796774eec6ae4eee1abc"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgencyPMG%2Fqueue-tactician","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgencyPMG%2Fqueue-tactician/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgencyPMG%2Fqueue-tactician/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgencyPMG%2Fqueue-tactician/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AgencyPMG","download_url":"https://codeload.github.com/AgencyPMG/queue-tactician/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235534342,"owners_count":19005470,"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":["command-bus","php","pmg-queue","pmg-queue-driver","queue","tactician"],"created_at":"2025-01-25T04:11:54.406Z","updated_at":"2025-01-25T04:11:54.995Z","avatar_url":"https://github.com/AgencyPMG.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pmg/queue-tactician\n\nThis is a middleware for [Tactician](http://tactician.thephpleague.com/) to\nintegrate it with [pmg/queue](https://github.com/AgencyPMG/Queue).\n\n## Installation and Usage\n\nInstall with composer.\n\n```\ncomposer require pmg/queue-tactician\n```\n\nTo use it, add the middleware to your middleware chain sometime before the\ndefault command handler middleware.\n\n```php\nuse League\\Tactician\\CommandBus;\nuse League\\Tactician\\Handler\\CommandHandlerMiddleware;\nuse PMG\\Queue\\Producer;\nuse PMG\\Queue\\Tactician\\QueueingMiddleware;\n\n/** @var Producer */\n$producer = createAQueueProducerSomehow();\n\n$bus = new CommandBus([\n    new QueueingMiddleware($producer),\n    new CommandHandlerMiddleware(/*...*/),\n]);\n```\n\n## Enqueueing Commands\n\nAny command that implements `PMG\\Queue\\Message` will be put into the queue via\nthe producer and no further middlewares will be called.\n\n```php\nuse PMG\\Queue\\Message;\n\nfinal class DoLongRunningStuff implements Message\n{\n    /**\n     * {@inheritdoc}\n     */\n    public function getName()\n    {\n        return 'LongRunningStuff';\n    }\n}\n\n// goes right into the queue\n$bus-\u003ehandle(new DoLongRunningStuff());\n```\n\n## Dequeueing (Consuming) Commands\n\n\nTo use tactician to process the messages via the consumer, use\n`PMG\\Queue\\Handler\\TacticianHandler`.\n\n```php\nuse PMG\\Queue\\DefaultConsumer;\nuse PMG\\Queue\\Handler\\TacticianHandler;\n\n/** @var League\\Tactician\\CommandBus $bus */\n$handler = new TacticianHandler($bus);\n\n/** @var PMG\\Queue\\Driver $driver */\n$consumer = new DefaultConsumer($driver, $handler);\n\n$consumer-\u003erun();\n```\n\nThe above assumes that the `CommandBus` instance still has the\n`QueueingMiddleware` installed. If not, you'll need to use your own handler that\ninvokes the command bus, perhaps via `CallableHandler`.\n\n```php\nuse League\\Tactician\\CommandBus;\nuse League\\Tactician\\Handler\\CommandHandlerMiddleware;\nuse PMG\\Queue\\DefaultConsumer;\nuse PMG\\Queue\\Message;\nuse PMG\\Queue\\Handler\\CallableHandler;\n\n// no QueueingMiddleware!\n$differentBus = new CommandBus([\n    new CommandHandlerMiddleware(/*...*/),\n]);\n\n$handler = new CallableHandler([$bus, 'handle']);\n\n/** @var PMG\\Queue\\Driver $driver */\n$consumer = new DefaultConsumer($driver, $handler);\n\n$consumer-\u003erun();\n```\n\n## Beware of Wrapping This Handler with `PcntlForkingHandler`\n\nThe shared instance of the command bus means that it's very likely that things\nlike open database connections will cause issues if/when a child press is forked\nto handle messages.\n\nInstead a better bet is to create a new command bus for each message.\n`CreatingTacticianHandler` can do that for you.\n\n```php\nuse League\\Tactician\\CommandBus;\nuse League\\Tactician\\Handler\\CommandHandlerMiddleware;\nuse PMG\\Queue\\Message;\nuse PMG\\Queue\\Handler\\CallableHandler;\nuse PMG\\Queue\\Tactician\\QueuedCommand;\nuse PMG\\Queue\\Tactician\\QueueingMiddleware;\nuse PMG\\Queue\\Handler\\CreatingTacticianHandler;\n\n$handler = new CreatingTacticianHandler(function () {\n    // this is invoked for every message\n    return new CommandBus([\n        new QueueingMiddleware(createAProduerSomehow()),\n        new CommandHandlerMiddlware(/* ... */)\n    ]);\n});\n\n/** @var PMG\\Queue\\Driver $driver */\n$consumer = new DefaultConsumer($driver, $handler);\n\n$consumer-\u003erun();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagencypmg%2Fqueue-tactician","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagencypmg%2Fqueue-tactician","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagencypmg%2Fqueue-tactician/lists"}