v3knet / queue-module
There is no license information available for the latest version (0.2.0) of this package.
0.2.0
2015-09-27 22:52 UTC
Requires
- php: >=5.5
- bernard/bernard: 1.0.*@dev
- dflydev/doctrine-orm-service-provider: ^2.0.0
- doctrine/cache: ^1.4.1
- doctrine/orm: ^2.5.0
- guzzlehttp/guzzle: ^6.0.2
- jms/serializer: ^1.0
- monolog/monolog: ^1.16.0
- phpdocumentor/reflection-docblock: ^2.0
- psr/log: ^1.0.0
- silex/silex: 2.0.x-dev
- swiftmailer/swiftmailer: ^5.4.1
- symfony/config: ^2.7.0
- symfony/console: ^2.7.0
- symfony/dependency-injection: ^2.7.0
- symfony/form: ^2.7.0
- symfony/security: ^2.7.0
- symfony/security-csrf: ^2.7.0
- symfony/serializer: ^2.7.0
- symfony/translation: ^2.7.0
- symfony/twig-bridge: ^2.7
- symfony/validator: ^2.7.0
- symfony/var-dumper: ^2.7.0
- symfony/yaml: ^2.7.0
- twig/twig: ^1.18
Requires (Dev)
- silex/web-profiler: 2.0.x-dev
- symfony/var-dumper: ^2.7.0
Suggests
- silex/web-profiler: silex/web-profiler 2.0.x-dev
README
With this module, we can put the message to queue, process the message using consumer.
1. Let the module know your queue
use atsilex\module\Module; use atsilex\module\system\events\AppEvent; use Pimple\Container; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Bernard\Message\DefaultMessage; class MyModule extends Module { public function subscribe(Container $container, EventDispatcherInterface $dispatcher) { $dispatcher->addListener('queue.queues.get', function (AppEvent $event) { $queues = $event->getSubject(); $queues['my_module.demo_queue'] = DefaultMessage::class; }); } }
Then your queue is listed on:
php public/index.php v3k:queue:list
2. Produce message
use atsilex\module\system\ModularAp; use Bernard\Message\DefaultMessage; $msg = new DefaultMessage('my_module.demo_queue, ['foo' => 'bar']); $app['bernard.producer']->produce($msg);
3. Process the message
We need to teach consumer how to route our message:
use atsilex\module\Module; use atsilex\module\system\events\AppEvent; use Bernard\Router\SimpleRouter; use Bernard\Message\DefaultMessage; use Pimple\Container; use Symfony\Component\EventDispatcher\EventDispatcherInterface; class MyModule extends Module { public function subscribe(Container $container, EventDispatcherInterface $dispatcher) { // … $dispatcher->addListener('queue.router.create', function (AppEvent $event) { $router = $event->getSubject(); $router->add('my_module.demo_queue', function (ImportMessage $m) use ($c) { // Logic to process the message }); }); } }
The message can now be routed correctly, now to process the message, just call the consume command:
php public/index.php v3k:queue:process my_module.demo_queue