private async Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs) { if (exceptionReceivedEventArgs.Exception is MessagingEntityNotFoundException) { // reinitalize all try { await manager.CreateIfNotExisted().ConfigureAwait(false); if (isTopic) { await manager.AddSubscribtionIfNotExisted(subscriptionId).ConfigureAwait(false); } } catch (Exception ex) { logger.LogError($"ServiceBus: failed to create client: {setting.ConnectionString}: {ex}"); } } logger.LogError(exceptionReceivedEventArgs.Exception, "Message handler encountered an exception"); var context = exceptionReceivedEventArgs.ExceptionReceivedContext; logger.LogDebug("Endpoint: {Endpoint}, Entity Path: {EntityPath}, Executing Action: {Action}", context.Endpoint, context.EntityPath, context.Action); }
public ServiceBusReceiver(ServiceBusSetting setting, IMessageProcessor <T> processor, ILoggerFactory logger) { this.logger = logger.CreateLogger <ServiceBusReceiver <T> >(); this.processor = processor; this.setting = setting; isTopic = setting.IsTopic; manager = new ServiceBusManager(setting, logger); manager.CreateIfNotExisted().Wait(); if (isTopic) { manager.AddSubscribtionIfNotExisted(subscriptionId).Wait(); } receiver = new MessageReceiver(setting.ConnectionString, isTopic ? $"{setting.TopicPath}/subscriptions/{subscriptionId}" : setting.QueueName); }