You are developing a C# background service that consumes events from an Azure Event Hub. The service must use the EventProcessorClient class from the Azure.Messaging.EventHubs.Processor library and utilize Azure Blob Storage for checkpointing and load balancing.
Which sequence of actions must you perform in your C# code to properly configure, run, and cleanly terminate the event processor?
- 1Instantiate a BlobContainerClient that points to the Azure Blob Storage container used for tracking partition ownership.
- 2Initialize the EventProcessorClient instance using the BlobContainerClient, consumer group, connection string, and Event Hub name.
- 3Bind custom event-handling and error-handling methods to the ProcessEventAsync and ProcessErrorAsync event properties.
- 4Call the StartProcessingAsync method on the EventProcessorClient to begin processing events.
- 5Call the StopProcessingAsync method on the EventProcessorClient when the application is shutting down.
Cevap
To implement the EventProcessorClient lifecycle, you must first instantiate a BlobContainerClient, then pass it to initialize the EventProcessorClient, next bind delegate handlers to the ProcessEventAsync and ProcessErrorAsync properties, then invoke StartProcessingAsync to start processing, and finally call StopProcessingAsync to gracefully shut down the consumer.
The correct order follows the standard lifecycle of EventProcessorClient initialization and operation. You must first create the storage client since the event processor client depends on it. Once the processor is instantiated, handlers must be registered before the client is started. Finally, the client must be stopped cleanly when shutting down.
Adım Adım Çözüm
Anahtar Kavram
Lifecycle of EventProcessorClient with Blob Storage Checkpointing