{"id":18924799,"url":"https://github.com/php-bundles/event-queue-bundle","last_synced_at":"2025-04-15T12:32:51.687Z","repository":{"id":57063661,"uuid":"59607510","full_name":"php-bundles/event-queue-bundle","owner":"php-bundles","description":"Symfony Event Queue Bundle","archived":false,"fork":false,"pushed_at":"2017-10-17T23:55:54.000Z","size":44,"stargazers_count":25,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T21:22:21.480Z","etag":null,"topics":["event","php","queue","redis","symfony","symfony-bundle"],"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/php-bundles.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}},"created_at":"2016-05-24T20:46:20.000Z","updated_at":"2022-09-16T14:24:52.000Z","dependencies_parsed_at":"2022-08-24T10:10:24.262Z","dependency_job_id":null,"html_url":"https://github.com/php-bundles/event-queue-bundle","commit_stats":null,"previous_names":["symfony-bundles/event-queue-bundle"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-bundles%2Fevent-queue-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-bundles%2Fevent-queue-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-bundles%2Fevent-queue-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-bundles%2Fevent-queue-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-bundles","download_url":"https://codeload.github.com/php-bundles/event-queue-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249072513,"owners_count":21208202,"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":["event","php","queue","redis","symfony","symfony-bundle"],"created_at":"2024-11-08T11:08:11.992Z","updated_at":"2025-04-15T12:32:51.456Z","avatar_url":"https://github.com/php-bundles.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"SymfonyBundlesEventQueueBundle\n==============================\n\n[![SensioLabsInsight][sensiolabs-insight-image]][sensiolabs-insight-link]\n\n[![Build Status][testing-image]][testing-link]\n[![Scrutinizer Code Quality][scrutinizer-code-quality-image]][scrutinizer-code-quality-link]\n[![Code Coverage][code-coverage-image]][code-coverage-link]\n[![Total Downloads][downloads-image]][package-link]\n[![Latest Stable Version][stable-image]][package-link]\n[![License][license-image]][license-link]\n\nInstallation\n------------\n\n* Require the bundle with composer:\n\n``` bash\ncomposer require symfony-bundles/event-queue-bundle\n```\n\n* Enable the bundle in the kernel:\n\n``` php\npublic function registerBundles()\n{\n    $bundles = [\n        // ...\n        new SymfonyBundles\\EventQueueBundle\\SymfonyBundlesEventQueueBundle(),\n        // ...\n    ];\n    ...\n}\n```\n\n* Configure the EventQueue bundle in your config.yml.\n\nDefaults configuration:\n\n``` yml\nsb_event_queue:\n    service_name: 'event_queue'\n    default_name: 'event:default'\n    storage_path: '%kernel.cache_dir%/event-queue-daemon.%s.pid'\n```\n\n* Configure the redis client in your config.yml. Read more about [RedisBundle configuration][redis-bundle-link].\n\nHow to use\n----------\n\nAdd an event to the queue:\n\n``` php\n$dispatcher = $this-\u003eget('sb_event_queue');\n\n$dispatcher-\u003eon(MyEvent::class, date('Y-m-d H:i:s'), 'Example message');\n```\n\nYour event class must implement `SymfonyBundles\\EventQueueBundle\\EventInterface`\n(or extending `SymfonyBundles\\EventQueueBundle\\Event` class)\nand having constant `NAME` with the event name. For example:\n\n``` php\nnamespace AppBundle\\Event;\n\nuse SymfonyBundles\\EventQueueBundle\\Event;\n\nclass MyEvent extends Event\n{\n    const NAME = 'event.example';\n\n    private $time;\n    private $message;\n\n    public function __construct($time, $message)\n    {\n        $this-\u003etime = $time;\n        $this-\u003emessage = $message;\n    }\n\n    public function getTime()\n    {\n        return $this-\u003etime;\n    }\n\n    public function getMessage()\n    {\n        return $this-\u003emessage;\n    }\n}\n```\n\nCreating an Event Listener.\nThe most common way to listen to an event is to register an event listener:\n\n``` php\nnamespace AppBundle\\EventListener;\n\nuse AppBundle\\Event\\MyEvent;\n\nclass MyListener\n{\n    public function onEventExample(MyEvent $event)\n    {\n        $event-\u003egetTime();\n        $event-\u003egetMessage();\n\n        // and we are doing something...\n    }\n}\n```\n\nNow that the class is created, you just need to register it as a service and notify Symfony that it is a \"listener\":\n\n``` yml\nservices:\n    app.my_listener:\n        class: AppBundle\\EventListener\\MyListener\n        tags:\n            - { name: kernel.event_listener, event: event.example }\n```\n\nExecution (dispatching) of all events from the queue:\n\n``` php\nwhile ($dispatcher-\u003ecount()) {\n    $dispatcher-\u003edispatch();\n}\n```\n\nYou can separate the events by section, specifying in event manager the needed section.\n\n``` php\n$dispatcher-\u003esetName('email.notifications');\n\n$dispatcher-\u003eon(EmailNotifyEvent::class, 'Subject', 'Message Body', ['john@domain.com', 'alex@domain.com']);\n$dispatcher-\u003eon(EmailNotifyEvent::class, 'Another subject', 'Another message Body', ['demo@domain.com']);\n\n$dispatcher-\u003esetName('database.reindex');\n\n$dispatcher-\u003eon(DatabaseReindexEvent::class, 'users');\n$dispatcher-\u003eon(DatabaseReindexEvent::class, 'orders');\n$dispatcher-\u003eon(DatabaseReindexEvent::class, 'products');\n```\n\nIn this example, will be executed only an events from the section `email.notifications`:\n\n``` php\n$dispatcher-\u003esetName('email.notifications');\n\nwhile ($dispatcher-\u003ecount()) {\n    $dispatcher-\u003edispatch();\n}\n```\n\nConsole commands:\n\n* `event:queue:dispatch`\n* `event:queue:daemon:start`\n* `event:queue:daemon:stop`\n\nIn what situations is useful to apply the queue of events:\n\n* When sending email messages\n* Parsing websites\n* and in other cases, when the execution time of process is very long,\nand the response from the server must be returned immediately.\n\n[package-link]: https://packagist.org/packages/symfony-bundles/event-queue-bundle\n[license-link]: https://github.com/symfony-bundles/event-queue-bundle/blob/master/LICENSE\n[license-image]: https://poser.pugx.org/symfony-bundles/event-queue-bundle/license\n[testing-link]: https://travis-ci.org/symfony-bundles/event-queue-bundle\n[testing-image]: https://travis-ci.org/symfony-bundles/event-queue-bundle.svg?branch=master\n[stable-image]: https://poser.pugx.org/symfony-bundles/event-queue-bundle/v/stable\n[downloads-image]: https://poser.pugx.org/symfony-bundles/event-queue-bundle/downloads\n[sensiolabs-insight-link]: https://insight.sensiolabs.com/projects/696a4b02-8d4c-45ca-924c-c61f8f06ed9e\n[sensiolabs-insight-image]: https://insight.sensiolabs.com/projects/696a4b02-8d4c-45ca-924c-c61f8f06ed9e/big.png\n[code-coverage-link]: https://scrutinizer-ci.com/g/symfony-bundles/event-queue-bundle/?branch=master\n[code-coverage-image]: https://scrutinizer-ci.com/g/symfony-bundles/event-queue-bundle/badges/coverage.png?b=master\n[scrutinizer-code-quality-link]: https://scrutinizer-ci.com/g/symfony-bundles/event-queue-bundle/?branch=master\n[scrutinizer-code-quality-image]: https://scrutinizer-ci.com/g/symfony-bundles/event-queue-bundle/badges/quality-score.png?b=master\n[redis-bundle-link]: https://github.com/symfony-bundles/redis-bundle#installation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-bundles%2Fevent-queue-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-bundles%2Fevent-queue-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-bundles%2Fevent-queue-bundle/lists"}