我正在尝试从运动学数据流中获取所有记录,以作为连续供稿显示在网页上。使用下面的PHP脚本,我不会获得使用aws代理(在服务器上)被推送到数据流中的所有记录。
我发现从getRecords()获取数据与使用流水使用者将S3中的数据登陆到同一数据流时丢失了数据
这是我正在使用的代码,有人可以指出我在做什么错
<?php
require 'vendor/autoload.php';
use Aws\Kinesis\KinesisClient;
$streamName = 'DATA-STREAM-NAME';
$kinesisClient = KinesisClient::factory(array(
'region' => 'eu-west-1',
'version' => '2013-12-02'
)
);
// Get shard list
$shardList = $kinesisClient->listShards([
'StreamName' => $streamName,
]);
// Iterate through shards to get iterators
$iterators = array();
foreach ($shardList['Shards'] as $shard) {
$shardIterator = $kinesisClient->getShardIterator([
'ShardId' => $shard['ShardId'],
'ShardIteratorType' => 'LATEST',
'StreamName' => $streamName
]);
$iterators[$shard['ShardId']] = $shardIterator['ShardIterator'];
}
// Loop continuously to get feed from kinesis
while (1) {
$iterators = getLogs($iterators);
sleep(3);
}
// Get records from each iterator
function getLogs($iterators) {
global $kinesisClient;
$nextIterators = array();
foreach ($iterators as $key => $iterator) {
$records = $kinesisClient->getRecords(['ShardIterator' => $iterator]);
$nextIterators[$key] = $records['NextShardIterator'];
if (empty($records['Records'])) {
return $nextIterators;
}
foreach ($records['Records'] as $data) {
echo $data['Data'];
}
}
return $nextIterators;
}