public async Task <IEventProcessorFactory> UnregisterEventMessageConsumerAsync(string name) { ConsumerConfigurationsOptions consumerConfiguration = GetConsumerConfiguration(name); List <EventProcessorHost> eventProcessorHostListRegistedList = EventProcessorHostList.Where(s => s.EventHubPath == consumerConfiguration.EventHubName).ToList(); IEventProcessorFactory returns = null; if (eventProcessorHostListRegistedList != null && eventProcessorHostListRegistedList.Any()) { foreach (var eventProcessorHostListRegisted in eventProcessorHostListRegistedList) { try { await eventProcessorHostListRegisted.UnregisterEventProcessorAsync(); EventProcessorHostList.Remove(eventProcessorHostListRegisted); returns = EventProcessorFactoryList[name]; EventProcessorFactoryList.Remove(name); } catch (Exception ex) { } } } return(returns); }
public async Task <bool> RegisterEventMessageConsumerAsync <TEventProcessor>(string name) where TEventProcessor : EventProcessorDefault { ConsumerConfigurationsOptions consumerConfiguration = GetConsumerConfiguration(name); if (EventProcessorHostList != null && EventProcessorHostList.Any(s => s.EventHubPath == consumerConfiguration.EventHubName)) { return(false); } eventProcessorHost = new EventProcessorHost( consumerConfiguration.EventHubName, !string.IsNullOrWhiteSpace(consumerConfiguration.ConsumerGroupName) ? consumerConfiguration.ConsumerGroupName : PartitionReceiver.DefaultConsumerGroupName, consumerConfiguration.ConnectionString, consumerConfiguration.StorageConnectionString, consumerConfiguration.StorageContainerName) { PartitionManagerOptions = new PartitionManagerOptions { RenewInterval = TimeSpan.FromSeconds(consumerConfiguration.RenewIntervalInSeconds), LeaseDuration = TimeSpan.FromSeconds(consumerConfiguration.LeaseDurationInSeconds) } }; var eventProcessorOptions = new EventProcessorOptions() { MaxBatchSize = consumerConfiguration.NumberOfEventsPerRequest, ReceiveTimeout = TimeSpan.FromSeconds(consumerConfiguration.ReceiveTimeoutInSeconds) }; DateTime offsetStartDateTime; if (!string.IsNullOrEmpty(consumerConfiguration.OffsetStartDateTime) && DateTime.TryParse(consumerConfiguration.OffsetStartDateTime, out offsetStartDateTime)) { eventProcessorOptions.InitialOffsetProvider = (partitionId) => EventPosition.FromEnqueuedTime(offsetStartDateTime); } else { eventProcessorOptions.InitialOffsetProvider = (partitionId) => EventPosition.FromStart(); } EventProcessorFactory <TEventProcessor> eventProcessorFactory = new EventProcessorFactory <TEventProcessor>(consumerConfiguration, ServiceProvider, Configuration); await eventProcessorHost.RegisterEventProcessorFactoryAsync(eventProcessorFactory, eventProcessorOptions); EventProcessorHostList.Add(eventProcessorHost); EventProcessorFactoryList.Add(name, eventProcessorFactory); return(true); }
public EventProcessorFactory(ConsumerConfigurationsOptions consumerConfiguration, IServiceProvider services, IConfiguration configuration) { var exceptionList = new List <Exception>(); if (services == null) { exceptionList.Add(new ArgumentNullException("services", "Could not be null.")); } if (configuration == null) { exceptionList.Add(new ArgumentNullException("configuration", "Could not be null.")); } if (exceptionList.Any()) { throw new AggregateException("One or more errors occured.", exceptionList); } var constructors = typeof(TEventProcessorDefault).GetConstructors(); if (constructors.Count() != 1) { throw new ArgumentOutOfRangeException("'TEventProcessor' should has one constructor."); } var parameters = constructors.First().GetParameters(); if (parameters.Count() != 3) { throw new ArgumentOutOfRangeException("'TEventProcessor' constructor should one constructor that containing the 3 parameters of EventProcessorDefault class."); } try { var checkInstance = (IEventProcessor)(Activator.CreateInstance(typeof(TEventProcessorDefault), ConsumerConfiguration, services, configuration)); } catch (Exception ex) { throw new ArgumentNullException($"{typeof(TEventProcessorDefault).FullName} constructor is invalid. Its should has only three parameters: System.Int32?, System.IServiceProvider, Microsoft.Extensions.Configuration.IConfiguration", ex); } Services = services; Configuration = configuration; ConsumerConfiguration = consumerConfiguration; }
public DeviceEventProcessor(ConsumerConfigurationsOptions consumerConfigurationsOptions, IServiceProvider serviceProvider, IConfiguration configuration) : base(consumerConfigurationsOptions, serviceProvider, configuration) { DeviceService = ServiceProvider.GetService <IDeviceService>(); EventHubProducerService = ServiceProvider.GetService <IEventHubProducerService>(); }
public EventProcessorDefault(ConsumerConfigurationsOptions consumerConfiguration, IServiceProvider serviceProvider, IConfiguration configuration) { ConsumerConfiguration = consumerConfiguration; ServiceProvider = serviceProvider; Configuration = configuration; }