You are developing a C# background service to process telemetry data from an Azure Event Hub. The service must use the EventProcessorClient to consume events, manage partition ownership, and store checkpoints in Azure Blob Storage.
What is the correct sequence of steps to initialize, run, and terminate the EventProcessorClient lifecycle?
- 1Instantiate a BlobContainerClient pointing to the Azure Storage account container designated for checkpointing and partition lease management.
- 2Instantiate the EventProcessorClient using the BlobContainerClient, consumer group, namespace connection string, and Event Hub name.
- 3Register callback methods for the ProcessEventAsync and ProcessErrorAsync event handlers on the processor client.
- 4Invoke the StartProcessingAsync method on the EventProcessorClient to start receiving events and managing partition load balancing.
- 5Invoke the StopProcessingAsync method on the EventProcessorClient when the application shuts down to gracefully release partition leases.
Answer
The correct sequence of steps is: 1) Instantiate a BlobContainerClient pointing to the Azure Storage account container designated for checkpointing. 2) Instantiate the EventProcessorClient using the BlobContainerClient, consumer group, namespace connection string, and Event Hub name. 3) Register callback methods for the ProcessEventAsync and ProcessErrorAsync event handlers on the processor client. 4) Invoke the StartProcessingAsync method on the EventProcessorClient. 5) Invoke the StopProcessingAsync method on the EventProcessorClient when the application shuts down.
The lifecycle of the EventProcessorClient requires a storage container to coordinate work across multiple processor instances. Therefore, the BlobContainerClient must be instantiated first, followed by the EventProcessorClient itself. Before starting the processor client, you must register handlers for event and error processing. Once registered, StartProcessingAsync starts the ingestion and processing loop, and StopProcessingAsync stops it gracefully during application shutdown.
Step-by-Step Solution
Key Concept
EventProcessorClient Lifecycle and Azure Blob Storage Checkpointing in .NET SDK