基于 swoole 的多进程消息同步微服务 -- (2)阿里云日志拉取实现与数据 check
function getLogs($startTime , $endTime, $logstore) {
$client = new Aliyun_Log_Client($this->endpoint, $this->accessKeyId, $this->accessKey);
$listShardRequest = new Aliyun_Log_Models_ListShardsRequest($this->project,$logstore);
$listShardResponse = $client -> listShards($listShardRequest);
$shardArr = $listShardResponse-> getShardIds();
foreach($shardArr as $shardId)
{
#对每一个 ShardId,先获取 Cursor 1511270484
$getCursorRequest = new Aliyun_Log_Models_GetCursorRequest($this->project,$logstore,$shardId,null, $startTime);
$response = $client -> getCursor($getCursorRequest);
$cursor = $response-> getCursor();
$count = 100;
while(true)
{
#从 cursor 开始读数据
$batchGetDataRequest = new Aliyun_Log_Models_BatchGetLogsRequest($this->project,$logstore,$shardId,$count,$cursor);
$response = $client -> batchGetLogs($batchGetDataRequest);
if($cursor == $response -> getNextCursor())
{
break;
}
if(!$this->handleOneArr($response,$endTime,$logstore)) {
break;
}
$cursor = $response -> getNextCursor();
}
}
}Last updated