Question

Difficulty: MediumProcess Azure Cosmos DB Change Feed Notifications

You are developing a C# background service that processes real-time transaction updates from an Azure Cosmos DB container using the .NET SDK v3 Change Feed Processor.

You need to initialize and run the Change Feed Processor.

In which order should you execute the steps? To answer, move all actions from the list of actions to the answer area and arrange them in the correct order.

  1. 1Obtain `Container` references for the monitored container and the lease container using the `CosmosClient`.
  2. 2Call `GetChangeFeedProcessorBuilder` on the monitored container, specifying a processor name and a delegate to handle the changed documents.
  3. 3Chain configuration methods such as `WithLeaseContainer` and `WithInstanceName` on the builder.
  4. 4Call `Build` on the builder to return a `ChangeFeedProcessor` instance.
  5. 5Invoke `StartAsync` on the `ChangeFeedProcessor` instance to start processing notifications.

Answer

The correct sequence of steps to initialize and start the Change Feed Processor is: 1) Obtain container references; 2) Call GetChangeFeedProcessorBuilder on the monitored container; 3) Chain configuration methods; 4) Call Build to create the processor instance; and 5) Call StartAsync to start processing notifications.
To configure the Change Feed Processor, you first get references to both containers. Then, you call `GetChangeFeedProcessorBuilder` on the monitored container. Next, you configure it by chaining configuration options like the lease container and host instance name. After configuration, you build the processor, and finally, you call `StartAsync` to begin receiving change notifications.

Step-by-Step Solution

1
Obtain container references
References to the monitored and lease containers are available.
Both container references are required during the builder configuration process.
2
Initialize the builder
A ChangeFeedProcessorBuilder instance is created.
The builder must be obtained from the monitored container reference while specifying the processor name and delegate.
3
Configure the builder
Lease container and instance name settings are applied to the builder.
These settings are required for the processor to manage leases and identify individual processor hosts.
4
Build the processor
A ChangeFeedProcessor instance is created.
The Build method consumes the configuration and instantiates the processor class.
5
Start the processor
The Change Feed Processor begins listening and processing updates.
StartAsync is needed to trigger the lease acquisition and start the change feed polling loop.

Key Concept

Initializing the Azure Cosmos DB Change Feed Processor using the .NET SDK v3.
Rate this question