This solution contains a set of Azure Functions that interact with Cosmos DB's Change Feed to sync counts by status. It's designed to demonstrate how to use Azure Functions and Cosmos DB's Change Feed together to process data in real-time.
- .NET 5.0 or later
- Azure Functions Core Tools
- An Azure Cosmos DB account
- Clone the repository to your local machine using
git clone <repository-url>
. - Open the solution in Visual Studio.
- Set up your Cosmos DB connection string in your
local.settings.json
file under the key "CosmosDb" OR put it in the User Secrets on WebApi level.
The solution is divided into next projects:
-
CosmosDb.ChangeFeed.Template.Application
: The main business logic including implementations ofICounter
is presented in this project. -
CosmosDb.ChangeFeed.Template.Domain
: This project contains the domain entities and enums used in the solution. It includes theProduct
andCounter
entities, as well as theProductStatus
enum. -
CosmosDb.ChangeFeed.Template.Persistence
: The project is responsible for configuration and interaction with Database. -
CosmosDb.ChangeFeed.Template.WebApi
: The controllers and models for communication are located in this project. -
CosmosDb.ChangeFeed.Template.Functions
: This project contains the Azure Functions that interact with Cosmos DB's Change Feed. The main function isSyncCountsByStatus
, which is triggered by changes in the Cosmos DB Change Feed.
CosmosDbTriggerFunction.cs
: This file contains theSyncCountsByStatus
function. This function is triggered by changes in the Cosmos DB Change Feed. For each document in the feed, it checks the product status and updates the corresponding counter in the Cosmos DB.
- Set up the Cosmos DB connection string in
local.settings.json
file under the key "CosmosDb" (or put it in the User Secrets) onCosmosDb.ChangeFeed.Template.WebApi
level. - Set up the Cosmos DB connection string in
local.settings.json
file under the key "CosmosDb" onCosmosDb.ChangeFeed.Template.Functions
level. - Start
CosmosDb.ChangeFeed.Template.WebApi
. - Start
CosmosDb.ChangeFeed.Template.Functions
. - Press F5 to start debugging. The Azure Functions runtime will start and your function will be ready to process changes from the Cosmos DB Change Feed.