Exemple #1
0
        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);
        }
Exemple #2
0
 public async Task UnregisterAllMessageConsumerAsync()
 {
     foreach (var EventProcessorHost in EventProcessorHostList)
     {
         await EventProcessorHost.UnregisterEventProcessorAsync();
     }
     EventProcessorHostList.RemoveAll(s => true);
     foreach (var eventProcessorFactoryItem in EventProcessorFactoryList)
     {
         EventProcessorFactoryList.Remove(eventProcessorFactoryItem.Key);
     }
 }
Exemple #3
0
        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);
        }