基于 swoole 实现的异步任务执行服务
任务延时达到秒级
自动将到时任务转发给消费服务, 无需服务主动轮询检查任务
DTProtocol
定义, 请求参数分两部分: action
和 message
, action
表示接口, message
表示数据包
Message::push
任务下发
http
$client = new Swoole\Client(SWOOLE_SOCK_TCP);
if (!$client->connect('127.0.0.1', 8847, -1)) {
exit("connect failed. Error: {$client->errCode}\n");
}
$messageBody = DelayTask\Lib\DTProtocol::encode([
'action' => 'Message::push', // 操作类型
'message' => [
$callbackMessage, // 回调消息体
$delay, // 延迟时长 (s)
$callbackProtocol, // 回调协议
[
'url' => $callbackUrl, // http作为回调协议时候的回调地址, 默认post方式回调
]
]
]);
$client->send($messageBody);
$res = $client->recv();
$resBody = DelayTask\Lib\DTProtocol::decode($res);
$client->close();