symfony-bundles/event-queue-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

symfony-bundles/event-queue-bundle

Composer 安装命令:

composer require symfony-bundles/event-queue-bundle

包简介

Symfony EventQueue Bundle

README 文档

README

SensioLabsInsight

Build Status Scrutinizer Code Quality Code Coverage Total Downloads Latest Stable Version License

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'

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:dispatch
  • event:queue:daemon:start
  • event: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 我们能提供哪些服务?
定制开发 / 二次开发

基于 symfony-bundles/event-queue-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12.81k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 25
  • Watchers: 6
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-24