1

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

2 Answers2

0

This is a bug with 3.15, you can track this here https://github.com/Azure/azure-cosmos-dotnet-v3/issues/2031.

Steve Johnson
  • 8,057
  • 1
  • 6
  • 17
  • But My question is what if I DONT WANT TO PROCESS ALL THE CHANGES and process only the changes that happened in last 7 days. I provide a WithStartTime value but i still get all the changes when i run it first time –  Dec 02 '20 at 07:50
  • So I created a new container, gave the Id for it as Lease Container in my above code and set Time to be (DateTime.Today.AddDays(-7).ToUniversalTime()) still I get all the documents from my monitored db. Have you tried this at your end? –  Dec 02 '20 at 12:26
0

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