Soru

Zorluk: OrtaImplement Azure Event Hubs Solutions

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?

  1. 1Instantiate a BlobContainerClient that points to the Azure Blob Storage container used for tracking partition ownership.
  2. 2Initialize the EventProcessorClient instance using the BlobContainerClient, consumer group, connection string, and Event Hub name.
  3. 3Bind custom event-handling and error-handling methods to the ProcessEventAsync and ProcessErrorAsync event properties.
  4. 4Call the StartProcessingAsync method on the EventProcessorClient to begin processing events.
  5. 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

1
Create the BlobContainerClient instance.
A client reference to the Azure Blob Storage container is established.
The EventProcessorClient constructor requires an object implementing the CheckpointStore pattern, which is fulfilled by BlobContainerClient.
2
Construct the EventProcessorClient.
The EventProcessorClient is initialized with the connection string, hub name, consumer group, and storage client.
This establishes the client with the configuration metadata needed to coordinate with other instances.
3
Assign event and error handlers.
The processor is configured to invoke user code on receiving events or encountering errors.
The processor client will fail to start if the ProcessEventAsync and ProcessErrorAsync handlers are not registered.
4
Invoke StartProcessingAsync.
The background processing threads start, partition ownership is balanced, and event reading commences.
This initiates the active processing lifecycle of the consumer.
5
Invoke StopProcessingAsync.
Events stop being processed, partition ownership is released, and connections are closed.
This ensures a graceful shutdown without leaving stale partition leases in blob storage.

Anahtar Kavram

Lifecycle of EventProcessorClient with Blob Storage Checkpointing
Bu soruyu puanla