AWS 运动不返回记录

AWS kinesis is not returning records

我要获取以下代码

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

它returns 0条失败记录 然后我运行跟随命令

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

aws kinesis get-records --shard-iterator xxxxxxxxx

它也是returns空数组。

有人可以帮助我吗? 谢谢

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

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

问:为什么 GetRecords 在我的 Amazon Kinesis 流中有数据时调用 return 空结果?

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

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