gpt4 book ai didi

amazon-web-services - AWS 运动不返回记录

转载 作者:行者123 更新时间:2023-12-05 02:20:33 24 4
gpt4 key购买 nike

我要获取以下代码

def getSample(accessKey: String, secretKey: String, streamName: String, size: Int, endpoint: String, region: String): Unit = {
var client=getKinesisClient(accessKey, secretKey, endpoint, region)
val decoder = Charset.forName("UTF-8").newDecoder()
var shards = getShards(accessKey, secretKey, streamName, endpoint, region)
val numberOfShards = shards.iterator()
var isStop = false
var sampleRecords = new StringBuilder
while (numberOfShards.hasNext() && !isStop) {
val shard = numberOfShards.next()
var shardIterator: String = null
val getShardIteratorRequest = new GetShardIteratorRequest()
getShardIteratorRequest.setStreamName(streamName)
getShardIteratorRequest.setShardId(shard.getShardId())
getShardIteratorRequest.setShardIteratorType("TRIM_HORIZON")
val getShardIteratorResult = client.getShardIterator(getShardIteratorRequest)
shardIterator = getShardIteratorResult.getShardIterator
var getRecordsRequest = new GetRecordsRequest
getRecordsRequest.setShardIterator(shardIterator)
var records: List[Record] = client.getRecords(getRecordsRequest).getRecords()
println(records.size())
var itr = records.iterator()
var SampleData = new ArrayList[String]()
while (itr.hasNext()) {
val record = itr.next()
val data = decoder.decode(record.getData).toString
println(data)
}
}
}

这会打印出记录数为 0。我用 aws cli 也是如此

aws kinesis put-records --records "Data=hello world - hemant,PartitionKey=20150421" --stream-name simpleStream

返回0条失败记录然后我按照命令运行

aws kinesis get-shard-iterator --stream-name simpleStream --shard-id 0 --shard-iterator-type TRIM_HORIZON

aws kinesis get-records --shard-iterator xxxxxxxxx

它也返回空数组。

有人可以帮帮我吗?谢谢

最佳答案

GetRecords 并不总是返回记录,即使分片中有记录也是如此。这在常见问题解答中有描述。

https://aws.amazon.com/kinesis/streams/faqs/

问:为什么 GetRecords 调用返回空结果,而我的 Amazon Kinesis 流中有数据?

您正在从 TRIM_HORIZON 位置请求记录,这是分片中最旧的位置。如果您连续多次调用 get-records(10 次或 20 次或更多次)并继续迭代器点,您将遇到记录。

以下论坛也很有用:: https://forums.aws.amazon.com/thread.jspa?messageID=509980

关于amazon-web-services - AWS 运动不返回记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38567528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com