ドキュメントを読んだ後、変更フィードを概念化するのが苦労しています。下のdocumentationのコードを見てみましょう。 2番目の変更フィードは、最後にチェックポイント経由で実行されたときから変更を取得しています。サマリーデータの作成に使用されているとし、問題があり、前回から再実行する必要があったとします。私は次のことを理解していません。DocumentDB変更フィードと保存チェックポイント
- チェックポイントを開始する特定の時間を指定する方法。チェックポイント辞書を保存して実行ごとに使用することができると理解していますが、X時間から変更してサマリーデータを再実行するにはどうすればよいでしょうか
- 2番目のサマリーデータを再実行し、集計された各データに使用されているので、そのデータがどこで中止されたかがわかります。レコードがそのチェックポイントの前または前にあることをどのように知っていますか?始まり、その後、最後のチェックポイントから収集から実行
コード:
Dictionary < string, string > checkpoints = await GetChanges(client, collection, new Dictionary < string, string >());
await client.CreateDocumentAsync(collection, new DeviceReading {
DeviceId = "xsensr-201", MetricType = "Temperature", Unit = "Celsius", MetricValue = 1000
});
await client.CreateDocumentAsync(collection, new DeviceReading {
DeviceId = "xsensr-212", MetricType = "Pressure", Unit = "psi", MetricValue = 1000
});
// Returns only the two documents created above.
checkpoints = await GetChanges(client, collection, checkpoints);
//
private async Task < Dictionary < string, string >> GetChanges(
DocumentClient client,
string collection,
Dictionary < string, string > checkpoints) {
List <PartitionKeyRange> partitionKeyRanges = new List <PartitionKeyRange>();
FeedResponse <PartitionKeyRange> pkRangesResponse;
do {
pkRangesResponse = await client.ReadPartitionKeyRangeFeedAsync(collection);
partitionKeyRanges.AddRange(pkRangesResponse);
}
while (pkRangesResponse.ResponseContinuation != null);
foreach(PartitionKeyRange pkRange in partitionKeyRanges) {
string continuation = null;
checkpoints.TryGetValue(pkRange.Id, out continuation);
IDocumentQuery <Document> query = client.CreateDocumentChangeFeedQuery(
collection,
new ChangeFeedOptions {
PartitionKeyRangeId = pkRange.Id,
StartFromBeginning = true,
RequestContinuation = continuation,
MaxItemCount = 1
});
while (query.HasMoreResults) {
FeedResponse <DeviceReading> readChangesResponse = query.ExecuteNextAsync <DeviceReading>().Result;
foreach(DeviceReading changedDocument in readChangesResponse) {
Console.WriteLine(changedDocument.Id);
}
checkpoints[pkRange.Id] = readChangesResponse.ResponseContinuation;
}
}
return checkpoints;
}
lucumaこれは、[email protected]とのより長い/オフラインの議論の恩恵を受けるかもしれない良い質問だと思います。 –
お返事ありがとうございました。ちょっと待ってください。 – lucuma