我正在创建一个我要恢复的未分区的更改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 回答
要读取更改源,必须使用
CreateDocumentChangeFeedQuery
(它永远不会重置ResponseContinuation),而不是ReadDocumentFeed
(当没有更多结果时,它设置为null) .有关示例,请参见https://docs.microsoft.com/en-us/azure/documentdb/documentdb-change-feed#working-with-the-rest-api-and-sdk .