首页 文章

DocumentDb优化未分区更改Feed的恢复

提问于
浏览
1

我正在创建一个我要恢复的未分区的更改Feed,例如每隔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”块 . 这样做是因为如果我把它留下来,responseContinuation被设置为null,这将基本上重新启动轮询周期,因为将请求延续设置为null将拉动更改源中的第一组文档 .

然而,缺点是每个轮询循环将重放前一组文档而不是任何其他更改 . 我可以做些什么来进一步优化这个或者这是更改Feed API的限制吗?

1 回答

相关问题