t4web/queue

ZF2 模块。消息代理软件实现

0.1.0 2016-06-22 15:19 UTC

This package is auto-updated.

Last update: 2024-08-26 17:28:09 UTC


README

ZF2 模块。消息代理软件实现

简介

包含部分

  • Server - 从队列获取消息并运行工作进程,监控运行中的工作进程数量
  • Producer - 产生消息并将它们发送到队列
  • Worker - 你的后台任务
  • Storage - 消息存储

工作流程

  • 客户端告诉 Producer 它想处理什么
  • Producer 创建消息并将其放入 Storage 并获取消息 ID。之后,通过 ID 推送服务器处理消息
  • Server 检查工作进程数量(如果运行的工作进程太多,等待)并运行带有消息 ID 的 Worker
  • Worker - 从存储中获取消息并处理它。
                               Server
                    message  /        \  run worker
Client -> Producer --------->          -------------> Worker
                             \                          /
                               Storage             --->-

我们提供了 2 个服务器

  1. 实时服务器 - 使用 ReactPHP 运行一个非阻塞服务器,通过套接字接收消息并在后台进程执行它们。
  2. 间隔服务器 - 通过间隔检查存储中的消息(由 cronjob 运行)

配置

只需将其添加到你的配置中

't4web-queue' => [

     'realtime-server' => [
         'enabled' => true,
         'hostname' => 'localhost',
         'port' => 4000,
     ],

     'queues' => [

         // Queue name
         'test-engine' => [

             // Handler class
             'handler' => EchoWorker::class,

             // count workers, optional, default 1
             'worker-count' => 1,

             // You can limit the amount of time a process takes to complete by setting a timeout (in seconds)
             // optional, default 300
             'timeout' => 300,

             // optional, default 0
             'debug-enable' => 1,
         ],
     ],
 ];

运行

$ php public/index.php queue realtime-server