ChangeFeed - 上次成功的操作已处理

时间:2017-01-19 12:36:42

标签: azure-cosmosdb

下面的代码段迭代了更改Feed。如果我们需要跟踪最后成功处理的记录是由循环中的continuation plus index(continuation + i)和/或文档的ETag计算的。如果出现故障,我该如何从确切位置查询更改进纸?目前尚不清楚,因为当我从0开始并请求1000时,我的测试中的延续令牌是1120.

IDocumentQuery < Document > query = client.CreateDocumentChangeFeedQuery(
 collectionUri,
 new ChangeFeedOptions {
  PartitionKeyRangeId = pkRange.Id,
   StartFromBeginning = true,
   RequestContinuation = continuation,
   MaxItemCount = 1000
 });

while (query.HasMoreResults) {

 Dictionary < string, BlastTimeRange > br = new Dictionary < string, BlastTimeRange > ();
 var readChangesResponse = query.ExecuteNextAsync < Document > ().Result;
 int i =0;
 foreach(Document changedDocument in readChangesResponse.AsEnumerable().ToList()) {
   // processing each one
   // the continuation and i represent the place or is it better to store off the ETag?  
 }

}

1 个答案:

答案 0 :(得分:0)

今天执行此操作的最佳方法是跟踪延续令牌(与REST API中的ETag相同),以及您在其中读取的文档的_rid值列表批次。当您阅读下一批时,您必须排除之前处理​​过的_rid值。

在不编写自定义代码的情况下执行此操作的最简单方法是使用DocumentDB团队的ChangeFeedProcessor库(在预览中)。为了获得访问权限。请发送电子邮件至askdocdb@microsoft.com。

相关问题