Warm tip: This article is reproduced from serverfault.com, please click

Cosmos Db Change Feed do not give the desired result

发布于 2020-12-01 14:29:15

I am trying to get all the changes from my monitored Db in the Cosmos db Change Feed by following the below codes. I am trying for different duration like the changes happening today or the changes happened in last 7 days or changes happened overall. Now in all the cases I get all the changes in first time and no changes in the second run unless there is a change coming. I would like to know what wrong am I doing here, and If I have to get changes for only last week on my each run, How should I configure the change feed if my below code is not correct. Thanks in Advance

 private static CosmosClient Client { get; set; }
    static void Main(string[] args)
    {
        Task.Run(async () =>
        {
            Client = new CosmosClient("AccountEndpoint = https://test.documents.azure.com:443/;AccountKey=FW5yvDA==;");
            var database = Client.GetDatabase("twstDatabase");
            var container = database.GetContainer("TestContainer");
            var leaseContainer = database.GetContainer("leases");

            var cfp = container.GetChangeFeedProcessorBuilder<dynamic>("cfpLibraryDThird", ProcessChanges)
                .WithLeaseContainer(leaseContainer)
                .WithInstanceName("Change Feed Instance Demo") 
// I change the instance name for different start time
                    .WithStartTime(DateTime.Today.AddDays(-7).ToUniversalTime())
                    //.WithStartTime(DateTime.MinValue.ToUniversalTime())
                    .Build();
                await cfp.StartAsync();
                Console.WriteLine("Started Change feed processor- press key to stop");
                Console.ReadKey(true);
                await cfp.StopAsync();
            }).Wait();
        }

        static async Task ProcessChanges(IReadOnlyCollection<dynamic> docs, CancellationToken cancellationToken)
        {
            foreach (var doc in docs)
            {
                Console.WriteLine($"Document {doc.id} has changed");
                
            }
        }
    }
}
Questioner
user2248618
Viewed
0
Vasyl Tserpiak 2020-12-28 21:37:13

It was fixed at 3.15.1. I updated the package and it fixes the problem.