我正在玩 kinesis,我尝试了非常简单的示例。我已经执行的步骤:执行生产者来放置一些成功的记录。
执行 getRecords 时在消费者端面临错误。我试图更改所有这些方法以从 api 获取记录:'AT_SEQUENCE_NUMBER | AFTER_SEQUENCE_NUMBER | TRIM_HORIZON | 最新的'。
回复:
Aws\Result Object
( [数据:Aws\Result:private] => 数组 ( [记录] => 数组 ( )
[NextShardIterator] => AAAAAAAAAA.....
[MillisBehindLatest] => 0
[@metadata] => Array
源代码:
$streamName = 'test';
$numberOfRecordsPerBatch = 10000;
require_once 'vendor/autoload.php';
$sdk = new \Aws\Sdk();
$kinesisClient = $sdk->createKinesis([
'region' => '{REGION}',
'version' => '2013-12-02',
'credentials' => [
'key' => '{API_KEY}',
'secret' => '{API_SECRET}'
]
]);
// get all shard ids
$res = $kinesisClient->describeStream([ 'StreamName' => $streamName ]);
$shardIds = $res->search('StreamDescription.Shards[].ShardId');
$count = 0;
$startTime = microtime(true);
foreach ($shardIds as $shardId) {
echo "ShardId: $shardId\n";
// get initial shard iterator
$res = $kinesisClient->getShardIterator([
'ShardId' => $shardId,
'ShardIteratorType' => 'LATEST', // 'AT_SEQUENCE_NUMBER| AFTER_SEQUENCE_NUMBER | TRIM_HORIZON|LATEST'
// 'StartingSequenceNumber' => '<string>',
'StreamName' => $streamName,
]);
$shardIterator = $res->get('ShardIterator');
do {
echo "Get Records\n";
$res = $kinesisClient->getRecords([
'Limit' => $numberOfRecordsPerBatch,
'ShardIterator' => $shardIterator
]);
$shardIterator = $res->get('NextShardIterator');
$localCount = 0;
foreach ($res->search('Records[].[SequenceNumber, Data]') as $data) {
list($sequenceNumber, $item) = $data;
echo "- [$sequenceNumber] $item\n";
$count++;
$localCount++;
}
echo "Processed $localCount records in this batch\n";
sleep(1);
} while ($localCount>0);
}
我也浏览了 AWS 文档,发现我们发送的所有详细信息都是正确的,但我们仍然没有收到任何回复记录。
谢谢