dev-master
9999999-devA Symfony2 bundle that enable asynchonous execution of event listeners.
MIT
The Requires
- php >=5.3.2
- symfony/symfony ~2.0
by CloseToMe
queue worker event listener
Wallogit.com
2017 © Pedro Peláez
A Symfony2 bundle that enable asynchonous execution of event listeners.
A Symfony2 bundle that enable asynchonous execution of event listeners., (*1)
As long as some conditions are met, no code changes are required for an application to use the bundle., (*2)
The bundle is made of two parts : a listener and a worker., (*3)
The listener : * is registered for the configured event, with maximum priority, * stops propagation of those events, * sends the serialized events to the queue., (*4)
The worker : * builds the list of application listeners for the configured event, * listens to the queue and deserializes received events, * executes the listeners., (*5)
beanstalk - other queues can be addedenable the bundle,, (*6)
install Socket_Beanstalk (http://github.com/davidpersson/beanstalk) in your vendors directory and configure autoload, (*7)
$loader->registerPrefixes(array(
[...]
'Socket_' => __DIR__.'/../vendor/beanstalk/src',
));
socloz_event_queue:
queue_type: beanstalkd
forward: [ my.event.name, my.event.name ]
serialize: mongoodm
beanstalkd:
host: 127.0.0.1
tube: event_queue
Other possible configuration options (with default values) :, (*8)
socloz_event_queue:
beanstalkd:
port: 11300
persistent: true
timeout: 1
$ app/console socloz:event_queue:worker [stop_after]
If used, stop_after enables to worker to stop after a certain number of seconds (warning : the test is done after a job has been executed)., (*9)
Events need to be serialized before being sent. Objects coming from the ORM/ODM usually cannot be serialized/deserialized using PHP builtin classes, therefore the bundle uses dedicated serializers., (*10)
For now, 2 basic serializers exist :, (*11)
serialize: mandango),serialize: mongoodm).They assume :, (*12)
getId method exists for ORM/ODM objects,getId method come from the ORM/ODM,I did not have time/wasn't able to find a solution for those. Feel free to contribute better serializers !, (*13)
ReflectionClass::newInstanceWithoutConstructor would help, but has only be added in 5.4. Class specific serializers, built during warm-up, would also improve performance if you need to forward a lot of events., (*14)
Example event class :, (*15)
<?php
namespace Socloz\APIBundle\Event\Event;
use Symfony\Component\EventDispatcher\Event;
class CategoryDeleteEvent extends Event
{
protected $category;
public function __construct($category)
{
$this->category = $category;
}
public function getCategory()
{
return $this->category;
}
}
If you need a serializer, it needs to implement the Socloz\EventQueueBundle\Serialize\SerializeInterface interface., (*16)
interface SerializeInterface
{
public function serialize($event);
public function deserialize($data);
}
It then needs to be registered as a service named socloz_event_queue.serialize.your_serializer_name and configured :, (*17)
socloz_event_queue:
serialize: your_serializer_name
If you want to use another transport (RabbitMQ, Zer0MQ, Gearman, ...), you need to implement the Socloz\EventQueueBundle\Queue\QueueInterface interface., (*18)
interface QueueInterface
{
public function put($job);
public function get();
public function delete($job);
}
get is a blocking call. delete is only required if get does not remove jobs from the queue., (*19)
The transport class should be registered as a service named socloz_event_queue.queue., (*20)
This bundle is released under the MIT license (see LICENSE)., (*21)
A Symfony2 bundle that enable asynchonous execution of event listeners.
MIT
queue worker event listener