github: http://github.com/brewlin/im-...
im-cloud分佈式中間件分析(三)-job節點實現
job 節點 做爲消費端,消費logic生產的數據,而後經過grpc推送至cloud節點,cloud點真正處理客戶端數據,job節點默認多進程消費啓動4個worker進程,以及默認10個grpc鏈接池
默認啓動4個worker進程消費logic請求,耗時處理投放至task進程處理,並轉發至cloud節點
須要在config/queue.php
,config/event.php
註冊相應的事件和相關配置php
use App\Consumer\Consumer; use Core\App; use Core\Swoole\WorkerStartInterface; use Swoole\Server as SwooleServer; class WorkerStartListener implements WorkerStartInterface { const INIT_LOGIC = 1; public function onWorkerStart(SwooleServer $server, int $workerId): void { if(App::isWorkerStatus()){ //啓動的n個 worker進程 分別做爲消費者進程消費,每一個進程會直接阻塞直到消費到數據 consumer()->consume(new Consumer()); } } }
Co::create(function()use($data){ if(empty(CloudClient::$serviceList)){ Log::error("cancle task deliver discovery cloud node is empty"); return; } Task::deliver(Job::class,"push",[CloudClient::$serviceList,$data]); },false); return Result::ACK;