v3knet/queue-module 问题修复 & 功能扩展

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

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

v3knet/queue-module

最新稳定版本:0.2.0

Composer 安装命令:

composer require v3knet/queue-module

包简介

README 文档

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-08-09