Symfony EventQueue Bundle

v2.0.1 2017-10-17 06:52 UTC

This package is auto-updated.

Last update: 2024-07-05 18:17:57 UTC




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


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

    service_name: 'event_queue'
    default_name: 'event:default'
    storage_path: '%kernel.cache_dir%/'

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)

        // 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":

        class: AppBundle\EventListener\MyListener
            - { name: kernel.event_listener, event: event.example }

Execution (dispatching) of all events from the queue:

while ($dispatcher->count()) {

You can separate the events by section, specifying in event manager the needed section.


$dispatcher->on(EmailNotifyEvent::class, 'Subject', 'Message Body', ['', '']);
$dispatcher->on(EmailNotifyEvent::class, 'Another subject', 'Another message Body', ['']);


$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:


while ($dispatcher->count()) {

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.