symfony-bundles/event-queue-bundle
Composer 安装命令:
composer require symfony-bundles/event-queue-bundle
包简介
Symfony EventQueue Bundle
README 文档
README
Installation
- Require the bundle with composer:
composer require symfony-bundles/event-queue-bundle
- Enable the bundle in the kernel:
public function registerBundles() { $bundles = [ // ... new SymfonyBundles\EventQueueBundle\SymfonyBundlesEventQueueBundle(), // ... ]; ... }
- Configure the EventQueue bundle in your config.yml.
Defaults configuration:
sb_event_queue: service_name: 'event_queue' default_name: 'event:default' storage_path: '%kernel.cache_dir%/event-queue-daemon.%s.pid'
- Configure the redis client in your config.yml. Read more about RedisBundle configuration.
How to use
Add an event to the queue:
$dispatcher = $this->get('sb_event_queue'); $dispatcher->on(MyEvent::class, date('Y-m-d H:i:s'), 'Example message');
Your event class must implement SymfonyBundles\EventQueueBundle\EventInterface
(or extending SymfonyBundles\EventQueueBundle\Event class)
and having constant NAME with the event name. For example:
namespace AppBundle\Event; use SymfonyBundles\EventQueueBundle\Event; class MyEvent extends Event { const NAME = 'event.example'; private $time; private $message; public function __construct($time, $message) { $this->time = $time; $this->message = $message; } public function getTime() { return $this->time; } public function getMessage() { return $this->message; } }
Creating an Event Listener. The most common way to listen to an event is to register an event listener:
namespace AppBundle\EventListener; use AppBundle\Event\MyEvent; class MyListener { public function onEventExample(MyEvent $event) { $event->getTime(); $event->getMessage(); // and we are doing something... } }
Now that the class is created, you just need to register it as a service and notify Symfony that it is a "listener":
services: app.my_listener: class: AppBundle\EventListener\MyListener tags: - { name: kernel.event_listener, event: event.example }
Execution (dispatching) of all events from the queue:
while ($dispatcher->count()) { $dispatcher->dispatch(); }
You can separate the events by section, specifying in event manager the needed section.
$dispatcher->setName('email.notifications'); $dispatcher->on(EmailNotifyEvent::class, 'Subject', 'Message Body', ['john@domain.com', 'alex@domain.com']); $dispatcher->on(EmailNotifyEvent::class, 'Another subject', 'Another message Body', ['demo@domain.com']); $dispatcher->setName('database.reindex'); $dispatcher->on(DatabaseReindexEvent::class, 'users'); $dispatcher->on(DatabaseReindexEvent::class, 'orders'); $dispatcher->on(DatabaseReindexEvent::class, 'products');
In this example, will be executed only an events from the section email.notifications:
$dispatcher->setName('email.notifications'); while ($dispatcher->count()) { $dispatcher->dispatch(); }
Console commands:
event:queue:dispatchevent:queue:daemon:startevent:queue:daemon:stop
In what situations is useful to apply the queue of events:
- When sending email messages
- Parsing websites
- and in other cases, when the execution time of process is very long, and the response from the server must be returned immediately.
symfony-bundles/event-queue-bundle 适用场景与选型建议
symfony-bundles/event-queue-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.81k 次下载、GitHub Stars 达 25, 最近一次更新时间为 2016 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「queue」 「symfony」 「event」 「bundle」 「dispatcher」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 symfony-bundles/event-queue-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 symfony-bundles/event-queue-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 symfony-bundles/event-queue-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Microservice RPC through message queues.
PHP AMQP Binding Library
The bundle for easy using json-rpc api on your project
A Laravel package to monitor queue jobs.
The CodeIgniter Redis package
贝嘟分布式缓存扩展
统计信息
- 总下载量: 12.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 26
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-05-24