I did get the code sample for the Cosmos DB change feed from this resource
I was able to successfully compile and run the code.
Here is the code for the change feed call
private static async Task<ChangeFeedProcessor> StartChangeFeedProcessorAsync(
CosmosClient cosmosClient,
IConfiguration configuration)
{
string databaseName = "changefeedsample";// configuration["SourceDatabaseName"];
string sourceContainerName = "source";// configuration["SourceContainerName"];
string leaseContainerName = "leases";// configuration["LeasesContainerName"];
Container leaseContainer = cosmosClient.GetContainer(databaseName, leaseContainerName);
ChangeFeedProcessor changeFeedProcessor = cosmosClient.GetContainer(databaseName, sourceContainerName)
.GetChangeFeedProcessorBuilder<ToDoItem>(processorName: "changeFeedSample", onChangesDelegate: HandleChangesAsync)
.WithInstanceName("consoleHost")
.WithLeaseContainer(leaseContainer)
.Build();
Console.WriteLine("Starting Change Feed Processor...");
await changeFeedProcessor.StartAsync();
Console.WriteLine("Change Feed Processor started.");
return changeFeedProcessor;
}
Here is the code for the action taken on a change feed
static async Task HandleChangesAsync(IReadOnlyCollection<ToDoItem> changes, CancellationToken cancellationToken)
{
Console.WriteLine("Started handling changes...");
foreach (ToDoItem item in changes)
{
Console.WriteLine($"Detected operation for item with id {item.id}, created at {item.creationTime}.");
// Simulate some asynchronous operation
await Task.Delay(10);
}
Console.WriteLine("Finished handling changes.");
}
I do see how the action can be triggered on an insert; however, is there a way to tell if there was an action taken on update. Is there a way to tell which is which, to tell one from another. Is there a way to get more details on an updated/added data
Thank you very much in advance