protected async Task InitializeAsync( string hostName, string eventHubName, string consumerGroupName, string eventHubConnectionString, string checkpointStorageAccount, int maxBatchSize, int prefetchCount, TimeSpan receiveTimeout, int maxConcurrencyPerProcessor, IEnumerable <Type> typesToSearch, Func <string, string, ICircuitBreaker> circuitBreakerFactory, IDispatcherInstrumentationPublisher instrumentationPublisher) { Logger.Info("Initializing event hub listener for {0} ({1})", eventHubName, consumerGroupName); // Get the consumer group via the Service Bus namespace (identifies the // consumer) var ns = NamespaceManager.CreateFromConnectionString(eventHubConnectionString); try { await ns.GetConsumerGroupAsync(eventHubName, consumerGroupName); Logger.Info("Found consumer group {1} for {0}", eventHubName, consumerGroupName); } catch (Exception e) { Logger.Error(e, "Could not establish connection to {0} in event hub {1}", consumerGroupName, eventHubName); throw; } var eventHubId = ConfigurationHelper.GetEventHubName(ns.Address, eventHubName); // Use a custom event processor factory to pass parameters to the // event host processor var factory = new EventProcessorFactory( handlerResolver: new MessageHandlerResolver(typesToSearch, DependencyResolverFactory.GetResolver()), maxConcurrency: maxConcurrencyPerProcessor, circuitBreakerFactory: circuitBreakerFactory, eventHubName: eventHubId, instrumentationPublisher: instrumentationPublisher); var options = new EventProcessorOptions { MaxBatchSize = maxBatchSize, PrefetchCount = prefetchCount, ReceiveTimeOut = receiveTimeout }; options.ExceptionReceived += options_ExceptionReceived; // Create the event processor host and register via the factory _host = new EventProcessorHost( hostName, consumerGroupName: consumerGroupName, eventHubPath: eventHubName, eventHubConnectionString: eventHubConnectionString, storageConnectionString: checkpointStorageAccount ); await _host.RegisterEventProcessorFactoryAsync(factory, options); Logger.Info("Event processor registered for {0} ({1})", eventHubName, consumerGroupName); }
protected async Task InitializeAsync( string hostName, string eventHubName, string consumerGroupName, string eventHubConnectionString, string checkpointStorageAccount, int maxBatchSize, int prefetchCount, TimeSpan receiveTimeout, int maxConcurrencyPerProcessor, IEnumerable<Type> typesToSearch, Func<string, string, ICircuitBreaker> circuitBreakerFactory, IDispatcherInstrumentationPublisher instrumentationPublisher) { Logger.Info("Initializing event hub listener for {0} ({1})", eventHubName, consumerGroupName); // Get the consumer group via the Service Bus namespace (identifies the // consumer) var ns = NamespaceManager.CreateFromConnectionString(eventHubConnectionString); try { await ns.GetConsumerGroupAsync(eventHubName, consumerGroupName); Logger.Info("Found consumer group {1} for {0}", eventHubName, consumerGroupName); } catch (Exception e) { Logger.Error(e, "Could not establish connection to {0} in event hub {1}", consumerGroupName, eventHubName); throw; } var eventHubId = ConfigurationHelper.GetEventHubName(ns.Address, eventHubName); // Use a custom event processor factory to pass parameters to the // event host processor var factory = new EventProcessorFactory( handlerResolver: new MessageHandlerResolver(typesToSearch, DependencyResolverFactory.GetResolver()), maxConcurrency: maxConcurrencyPerProcessor, circuitBreakerFactory: circuitBreakerFactory, eventHubName: eventHubId, instrumentationPublisher: instrumentationPublisher); var options = new EventProcessorOptions { MaxBatchSize = maxBatchSize, PrefetchCount = prefetchCount, ReceiveTimeOut = receiveTimeout }; options.ExceptionReceived += options_ExceptionReceived; // Create the event processor host and register via the factory _host = new EventProcessorHost( hostName, consumerGroupName: consumerGroupName, eventHubPath: eventHubName, eventHubConnectionString: eventHubConnectionString, storageConnectionString: checkpointStorageAccount ); await _host.RegisterEventProcessorFactoryAsync(factory, options); Logger.Info("Event processor registered for {0} ({1})", eventHubName, consumerGroupName); }