承接 keystone/tactician-deferred 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

keystone/tactician-deferred

Composer 安装命令:

composer require keystone/tactician-deferred

包简介

A Tactician middleware to allow commands to be handled asynchronously

README 文档

README

Build Status

A Tactician middleware to allow commands to be handled asynchronously using Keystone Queue.

Features:

  • Unobtrusive API to allow asynchronous handling of commands.
  • Publish command messages to any queue.
  • Commands can be retried on failure.

Installation

Install via Composer

composer require --dev keystone/tactician-deferred

Usage

Create a command class that implemented DeferrableCommand to tell the middleware to handle it asynchronously.

use Keystone\Tactician\Deferred\Command\DeferrableCommand;

class SendWelcomeCommand implements DeferrableCommand
{
    public $email;
    public $name;

    public function __construct(string $email, string $name)
    {
        $this->email = $email;
        $this->name = $name;
    }

    public function getKey(): string
    {
        // The command key is used to determine which queue to publish to.
        return 'email';
    }
}

Create a command handler as normal using your desired inflector method.

class SendWelcomeHandler
{
    public function handle(SendWelcomeCommand $command)
    {
        // Send the welcome
    }
}

When the command is handled by the command bus the middleware will publish a message to the queue and halt the handler. The message will then be received by the consumer and the worker will delegate the command to the command bus. Since the command will be serialized within the queue it's properties should be simple scalar values.

$commandBus = new CommandBus([new DeferredMiddleware(...), new CommandHandlerMiddleware(...)]);
$commandBus->handle(new SendWelcomeCommand('ben@flowerpots.com', 'Ben'));

Consume the messages in a long running process (see Keystone Queue for more information).

use Keystone\Queue\Consumer;
use Keystone\Queue\Provider;

$provider = new Provider(...);
$consumer = new Consumer($provider, ...);
// The consumer will poll the queue for new messages and process them.
$consumer->consume();

When the middleware is not configured the command will be handled synchronously as normal, which can be useful for testing without worrying about asynchronous processes in development environments.

Credits

License

Released under the MIT Licence. See the bundled LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固