1
votes

I am creating an un-partitioned change feed that I want to resume e.g. poll for new changes every X seconds. The checkpoint variable below holds the last response continuation response.

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

Note the use of the "if" block around the checkpoint. This is done because if I leave this out the responseContinuation gets set to null, which will basically restart the polling cycle as setting the request continuation to null will pull the 1st set of documents in the change feed.

However, the downside is each polling loop will replay the previous set of documents rather than just any additional changes. Is there anything I can do in order to optimized this further or is this a limitation of the change feed API?

1

1 Answers

1
votes

In order to read change feed, you must use CreateDocumentChangeFeedQuery (which never resets ResponseContinuation), instead of ReadDocumentFeed (which sets to null when there are no more results).

See https://docs.microsoft.com/en-us/azure/documentdb/documentdb-change-feed#working-with-the-rest-api-and-sdk for a sample.