2017 © Pedro Peláez
 

symfony-bundle event-queue-bundle

Symfony EventQueue Bundle

image

symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  • Wednesday, October 18, 2017
  • by khaperets
  • Repository
  • 6 Watchers
  • 20 Stars
  • 7,248 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 28 % Grown

The README.md

SymfonyBundlesEventQueueBundle

SensioLabsInsight, (*1)

![Build Status][testing-image] [Scrutinizer Code Quality][scrutinizer-code-quality-link] [Code Coverage][code-coverage-link] Total Downloads Latest Stable Version License, (*2)

Installation

  • Require the bundle with composer:

``` bash composer require symfony-bundles/event-queue-bundle, (*3)


* Enable the bundle in the kernel: ``` php public function registerBundles() { $bundles = [ // ... new SymfonyBundles\EventQueueBundle\SymfonyBundlesEventQueueBundle(), // ... ]; ... }
  • Configure the EventQueue bundle in your config.yml.

Defaults configuration:, (*4)

``` yml sb_event_queue: service_name: 'event_queue' default_name: 'event:default' storage_path: '%kernel.cache_dir%/event-queue-daemon.%s.pid', (*5)


* Configure the redis client in your config.yml. Read more about [RedisBundle configuration][redis-bundle-link]. How to use ---------- Add an event to the queue: ``` php $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:, (*6)

``` php namespace AppBundle\Event;, (*7)

use SymfonyBundles\EventQueueBundle\Event;, (*8)

class MyEvent extends Event { const NAME = 'event.example';, (*9)

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;
}

}, (*10)


Creating an Event Listener. The most common way to listen to an event is to register an event listener: ``` php 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":, (*11)

``` yml services: app.my_listener: class: AppBundle\EventListener\MyListener tags: - { name: kernel.event_listener, event: event.example }, (*12)


Execution (dispatching) of all events from the queue: ``` php while ($dispatcher->count()) { $dispatcher->dispatch(); }

You can separate the events by section, specifying in event manager the needed section., (*13)

``` php $dispatcher->setName('email.notifications');, (*14)

$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']);, (*15)

$dispatcher->setName('database.reindex');, (*16)

$dispatcher->on(DatabaseReindexEvent::class, 'users'); $dispatcher->on(DatabaseReindexEvent::class, 'orders'); $dispatcher->on(DatabaseReindexEvent::class, 'products');, (*17)


In this example, will be executed only an events from the section `email.notifications`: ``` php $dispatcher->setName('email.notifications'); while ($dispatcher->count()) { $dispatcher->dispatch(); }

Console commands:, (*18)

  • event:queue:dispatch
  • event:queue:daemon:start
  • event:queue:daemon:stop

In what situations is useful to apply the queue of events:, (*19)

  • 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.

The Versions

18/10 2017

dev-master

9999999-dev https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event

18/10 2017

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event

17/10 2017

v2.0.1

2.0.1.0 https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event

16/06 2016

dev-dev

dev-dev https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event

16/06 2016

v2.0.0

2.0.0.0 https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event

02/06 2016

v1.0.3

1.0.3.0 https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event

30/05 2016

v1.0.2

1.0.2.0 https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event

25/05 2016

v1.0.1

1.0.1.0 https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event

24/05 2016

v1.0.0

1.0.0.0 https://github.com/symfony-bundles/event-queue-bundle

Symfony EventQueue Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Khaperets

redis bundle dispatcher symfony queue event