从dynamodb流中读取数据 [英] Reading data from dynamodb streams

查看:84
本文介绍了从dynamodb流中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用于发电机表的设置流。我正在按照文档中的示例程序从流中读取数据( http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.LowLevel.Walkthrough.CompleteProgram.html )。但是我有一个问题-遍历分片时的
似乎检查分片者是否为null不足以退出循环。我的代码陷入无限循环。在示例程序中,对更改次数进行计数,并用于退出循环->

I have setup streams for my dynamo tables. I was following the example program in the documentation for reading the data from the streams(http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.LowLevel.Walkthrough.CompleteProgram.html). However I have a problem - when iterating through the shards it seems like checking for a sharditerator to be null is not a sufficient condition to exit the loop. My code gets into an infinite loop. In the example program the number of changes is counted and that is used to exit the loop -->

while (nextItr != null && numChanges > 0) {

   // Use the iterator to read the data records from the shard

  GetRecordsResult getRecordsResult = 
          streamsClient.getRecords(new GetRecordsRequest().
          withShardIterator(nextItr));
   List<Record> records = getRecordsResult.getRecords();
   System.out.println("Getting records...");
   for (Record record : records) {
           System.out.println(record);
            numChanges--;
    }
    nextItr = getRecordsResult.getNextShardIterator();
}

但是在真实环境中,我确信维护更改列表不切实际。设计是否意味着无限循环?为什么shardIterator不会变为空?

But in a real environment I am sure maintaining the list of changes is not practical. Is the design meant to be an infinite loop? Why does the shardIterator not become null?

推荐答案

我要重复我对您在 AWS论坛此处:

I'm repeating my answer to the same question you posted on AWS Forums here:

只要分片处于打开状态并且正在积极接收将来的更新,nextIterator就不会为空。一旦分片关闭并且遍历了最后一条记录,则您的循环可能会退出并指示不再有可能从分片中获取更多记录。

The nextIterator will not become null as long as the shard is open and is actively receiving possible future updates. Once the shard closes and the last record has been traversed, then your loop could exit and indicate there it is no longer possible to get more records from the shard.

请参考此处的文档: http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/model/GetRecordsResult.html#getNextShardIterator()

如果设置为null,则分片已关闭,请求的迭代器将不再返回任何数据。

"If set to null, the shard has been closed and the requested iterator will not return any more data."

希望能有所帮助,谢谢您对DynamoDB的兴趣!

Hope that helps, thanks for your interest in DynamoDB!

这篇关于从dynamodb流中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆