gpt4 book ai didi

azure - DocumentDb 优化非分区变更源的恢复

转载 作者:行者123 更新时间:2023-12-03 03:08:56 24 4
gpt4 key购买 nike

我正在创建一个未分区的更改源,我想恢复它,例如每 X 秒轮询一次新更改。下面的检查点变量保存最后一个响应继续响应。

    private string checkpoint;

private async Task ReadEvents()
{
FeedResponse<dynamic> feedResponse;
do
{
feedResponse = await client.ReadDocumentFeedAsync(commitsLink, new FeedOptions
{
MaxItemCount = this.subscriptionOptions.MaxItemCount,
RequestContinuation = checkpoint
});

if (feedResponse.ResponseContinuation != null)
{
checkpoint = feedResponse.ResponseContinuation;
}

// Code to process docs goes here...

} while (feedResponse.ResponseContinuation != null);
}

注意检查点周围“if” block 的使用。这样做是因为如果我忽略它,responseContinuation 就会设置为 null,这基本上会重新启动轮询周期,因为将请求延续设置为 null 会在更改源中提取第一组文档。

但是,缺点是每个轮询循环都会重播前一组文档,而不仅仅是任何其他更改。我可以做些什么来进一步优化这一点,还是这是更改源 API 的限制?

最佳答案

为了读取更改源,您必须使用 CreateDocumentChangeFeedQuery (它永远不会重置 ResponseContinuation),而不是 ReadDocumentFeed (当没有更多结果时设置为 null) .

参见https://learn.microsoft.com/en-us/azure/documentdb/documentdb-change-feed#working-with-the-rest-api-and-sdk获取示例。

关于azure - DocumentDb 优化非分区变更源的恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41473208/

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