In case of performing manual failover operation on event hub namespace, consumer application with EventProcessorClient which is continuously listening to event hub with alias name connection string failed as checkpoint store value changes while event hub namespace switch to secondary namespace.
To resolve we are using ProcessErrorAsync event to again initialize new EventProcessorClient and start listening again with StartProcessingAsync() method and also clearing existing checkpoint store blob.
Is it the correct way or any better approach recommended?
Sample code -
protected async Task ProcessErrorHandler(ProcessErrorEventArgs eventArgs)
{
if (eventArgs.Exception.InnerException is AmqpException && ((System.Type)((System.Reflection.MethodInfo)eventArgs.Exception.InnerException.TargetSite).DeclaringType).Name is "ExceptionDispatchInfo")
{
await processor.StopProcessingAsync();
processor = new EventProcessorClient(storageClient, _consumerGroup,
_ehubNamespaceConnectionString, _eventHubName);
await ClearCheckpointStore();// only to delete existing checkpoint file. so that it will create new checkpoint file with eventhub namespace2 checkpoint values.
// Register handlers for processing events and handling errors
processor.ProcessEventAsync += ProcessEventHandler;
processor.ProcessErrorAsync += ProcessErrorHandler;
await processor.StartProcessingAsync();
}
else
{
// handle other exception needed.
}
}