【问题标题】:How does DocumentDB changefeed support resume/continuation?DocumentDB changefeed 如何支持恢复/继续?
【发布时间】:2016-12-22 01:35:01
【问题描述】:

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

这里的参数是延续令牌和最大项目数。 如果我理解正确,您可以从 continuation token = null 开始。 您请求最多 x 个项目,如果有更多可用项目,响应中会附带一个延续令牌。这样,您就知道另一个变更集可用。

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

但是,下次您请求 API 时,您没有继续令牌来继续... 这会导致整个数据库作为变更集吗?我怎样才能防止这种情况? 我是否需要使用曾经使用过的最新令牌调用 API?这是否会导致某些更改需要再次处理?

【问题讨论】:

    标签: c# azure azure-cosmosdb


    【解决方案1】:

    使用更改提要,您始终可以返回一个继续标记(与查询和读取提要不同,在没有更多结果时不会返回继续标记)。

    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

    【讨论】:

    • 感谢您的回复!我注意到 CreateDocumentChangeFeedQuery 在 IDocumentClient 接口上不可用,而仅在 DocumentClient 类中可用。任何想法为什么?
    • 这将在下一个版本中添加。我们希望在这样做之前获得反馈,因为这将需要为已经实现 IDocumentClient 的 DocumentDB 用户重新编译(以及如何实现新的存根方法)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2011-11-16
    • 2011-01-16
    相关资源
    最近更新 更多