gpt4 book ai didi

c# - DocumentDB 变更源如何支持恢复/继续?

转载 作者:行者123 更新时间:2023-11-30 20:32:33 25 4
gpt4 key购买 nike

DocumentDB 最近发布了更改源。通过 API,您可以请求变更集。

这里的参数是连续标记和最大项目计数。如果我正确地理解了这一点,那么您将从继续标记 = null 开始。您请求最多 x 个项目,如果有更多可用项目,响应中会附带一个继续 token 。这样,您就知道另一个变更集可用。

如果响应中的继续标记为空,则您将获得所有结果。

但是,下次请求 API 时,您没有继续 token 来继续...这会导致完整的数据库作为变更集吗?我怎样才能防止这种情况发生?我是否需要使用最新使用过的 token 来调用 API?这会导致一些更改需要第二次处理吗?

最佳答案

使用更改源,您始终会得到一个继续 token (与查询和读取源不同,当没有更多结果时不会返回继续 token )。

IDocumentQuery<Document> query = client.CreateDocumentChangeFeedQuery(
collectionUri,
new ChangeFeedOptions
{
PartitionKeyRangeId = pkRange.Id,
StartFromBeginning = true,
RequestContinuation = continuation, // From last call to change feed
MaxItemCount = -1
});

// Paginate through all results currently available
while (query.HasMoreResults)
{
FeedResponse<DeviceReading> readChangesResponse = query.ExecuteNextAsync<DeviceReading>().Result;

foreach (DeviceReading changedDocument in readChangesResponse)
{
Console.WriteLine("\tRead document {0} from the change feed.", changedDocument.Id);
numChangesRead++;
}

// Save token for resuming after some time
checkpoints[pkRange.Id] = readChangesResponse.ResponseContinuation;
}

请参阅https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/code-samples/ChangeFeed/Program.cs#L127举个例子。

关于c# - DocumentDB 变更源如何支持恢复/继续?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41245637/

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