Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does DocumentDB changefeed support resume/continuation?

DocumentDB has recently released the change feed. Via the API you can request the changesets.

Parameters here are continuation token & max item count. If I got this correctly, you start with continuation token = null. You request max x items, and if there are more items available, a continuation token comes with the response. This way, you know another changeset is available.

If the continuation token in the response is empty, you got all result.

However, the next time you request the API, you don't have a continuation token to continue... Will this result in the full database as changeset? How can I prevent this? Do I need to call the API with the latest token ever used? Will this result in some changes that will be handled a second time?

like image 858
Identity Avatar asked Dec 20 '25 15:12

Identity


1 Answers

With Change Feed, you always get a continuation token back (unlike query and read-feed which do not return a continuation token when there are no more results).

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;
}

Please see https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/code-samples/ChangeFeed/Program.cs#L127 for an example.

like image 146
Aravind Krishna R. Avatar answered Dec 23 '25 04:12

Aravind Krishna R.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!