Question

Difficulty: HardProcess Azure Cosmos DB Change Feed Notifications

You are developing a microservice using the Azure Cosmos DB .NET SDK v3. You need to configure a Change Feed Processor to process document updates from a monitored container and coordinate state using a lease container. Which sequence of steps must you perform to initialize and run the Change Feed Processor?

  1. 1Retrieve Container references for both the monitored container and the lease container from the Cosmos client.
  2. 2Call GetChangeFeedProcessorBuilder on the monitored container, passing the processor name and the change handler delegate.
  3. 3Chain builder configuration methods to specify the current host instance name and attach the lease container reference.
  4. 4Call Build on the builder instance to construct the ChangeFeedProcessor object.
  5. 5Call StartAsync on the ChangeFeedProcessor instance to begin reading the change feed.

Answer

Retrieve container references, call GetChangeFeedProcessorBuilder on the monitored container, chain builder configuration methods (WithInstanceName and WithLeaseContainer), call Build, and then call StartAsync on the processor.
To successfully configure and run the Change Feed Processor, you must follow the correct lifecycle sequence: first obtain the container references, then initialize the builder on the monitored container, chain configuration methods such as the lease container and instance name, build the processor, and finally start it asynchronously.

Step-by-Step Solution

1
Obtain Container references from the Cosmos client.
Two Container instances representing the monitored source container and the lease storage container.
The processor builder requires references to both the data source and the lease coordinator containers to establish communication.
2
Invoke GetChangeFeedProcessorBuilder on the monitored container.
A ChangeFeedProcessorBuilder instance is initialized.
This starts the fluent configuration chain on the monitored container where the data changes originate.
3
Configure the builder with WithInstanceName and WithLeaseContainer.
The builder is configured with the specific worker host ID and lease container tracking.
The lease container is required for tracking checkpoints, and the instance name uniquely identifies this host for scale-out distribution.
4
Call Build on the builder.
A ChangeFeedProcessor instance is created.
This instantiates the engine that coordinates partition ownership and reads feed batches.
5
Call StartAsync on the processor instance.
The background change processing loop begins executing.
The processor requires an explicit start signal to allocate partition leases and begin streaming updates to the delegate.

Key Concept

Azure Cosmos DB .NET SDK v3 Change Feed Processor lifecycle and builder sequence
Rate this question