Exemple #1
0
 public EventReceiver(IEventProcessorFactory processorFactory, string eventHubName, string consumerGroupName, 
     string eventHubConnectionString, string checkpointConnectionString)
 {
     _processorFactory = processorFactory;
     _host = new EventProcessorHost(Environment.MachineName, eventHubName, consumerGroupName,
         eventHubConnectionString, checkpointConnectionString);
 }
        /// <summary>
        /// This registers <see cref="IEventProcessorFactory"/> implementation with the host which is used to create an instance of
        /// <see cref="IEventProcessor"/> when it takes ownership of a partition.  This also starts the host and causes it to start participating
        /// in the partition distribution process.
        /// </summary>
        /// <param name="factory">Instance of <see cref="IEventProcessorFactory"/> implementation.</param>
        /// <returns>A task to indicate EventProcessorHost instance is started.</returns>
        public Task RegisterEventProcessorFactoryAsync(IEventProcessorFactory factory)
        {
            var epo = EventProcessorOptions.DefaultOptions;

            epo.ReceiveTimeout = TimeSpan.MinValue;
            return(RegisterEventProcessorFactoryAsync(factory, epo));
        }
Exemple #3
0
        public AgentTest()
        {
            var blobStorageConfigMock = new Mock <IBlobStorageConfig>();

            this.logMock = new Mock <ILogger>();

            this.deviceGroupsWriterMock        = new Mock <IDeviceGroupsWriter>();
            this.deviceGroupsClientMock        = new Mock <IDeviceGroupsClient>();
            this.eventProcessorHostWrapperMock = new Mock <IEventProcessorHostWrapper>();
            var servicesConfigMock = new Mock <IServicesConfig>();

            servicesConfigMock.Setup(x => x.EventHubCheckpointTimeMs).Returns(60000);

            this.eventHubStatusMock    = new Mock <IEventHubStatus>();
            this.eventProcessorFactory = new DeviceEventProcessorFactory(this.eventHubStatusMock.Object, servicesConfigMock.Object, this.logMock.Object);

            this.threadMock = new Mock <IThreadWrapper>();

            this.deviceGroupsAgent = new Agent(
                this.deviceGroupsWriterMock.Object,
                this.deviceGroupsClientMock.Object,
                this.eventProcessorHostWrapperMock.Object,
                this.eventProcessorFactory,
                this.eventHubStatusMock.Object,
                servicesConfigMock.Object,
                blobStorageConfigMock.Object,
                this.logMock.Object,
                this.threadMock.Object);
        }
Exemple #4
0
        public ConfigurationBuilder(Configuration copyFrom)
        {
            _allAttributesPrivate = copyFrom.AllAttributesPrivate;
            _baseUri                     = copyFrom.BaseUri;
            _diagnosticOptOut            = copyFrom.DiagnosticOptOut;
            _diagnosticRecordingInterval = copyFrom.DiagnosticRecordingInterval;
            _eventCapacity               = copyFrom.EventCapacity;
            _eventFlushInterval          = copyFrom.EventFlushInterval;
            _eventProcessorFactory       = copyFrom.EventProcessorFactory;
#pragma warning disable 618
            _eventSamplingInterval = copyFrom.EventSamplingInterval;
#pragma warning restore 618
            _eventsUri             = copyFrom.EventsUri;
            _featureStore          = copyFrom.FeatureStore;
            _featureStoreFactory   = copyFrom.FeatureStoreFactory;
            _httpClientHandler     = copyFrom.HttpClientHandler;
            _httpClientTimeout     = copyFrom.HttpClientTimeout;
            _inlineUsersInEvents   = copyFrom.InlineUsersInEvents;
            _isStreamingEnabled    = copyFrom.IsStreamingEnabled;
            _offline               = copyFrom.Offline;
            _pollingInterval       = copyFrom.PollingInterval;
            _privateAttributeNames = copyFrom.PrivateAttributeNames is null ? null :
                                     new HashSet <string>(copyFrom.PrivateAttributeNames);
            _readTimeout            = copyFrom.ReadTimeout;
            _reconnectTime          = copyFrom.ReconnectTime;
            _sdkKey                 = copyFrom.SdkKey;
            _startWaitTime          = copyFrom.StartWaitTime;
            _streamUri              = copyFrom.StreamUri;
            _updateProcessorFactory = copyFrom.UpdateProcessorFactory;
            _useLdd                 = copyFrom.UseLdd;
            _userKeysCapacity       = copyFrom.UserKeysCapacity;
            _userKeysFlushInterval  = copyFrom.UserKeysFlushInterval;
            _wrapperName            = copyFrom.WrapperName;
            _wrapperVersion         = copyFrom.WrapperVersion;
        }
Exemple #5
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);
        }
 public Processor(int eventBatchMaximumCount, string consumerGroup, string connectionString, string eventHubName, EventProcessorOptions options, IEventProcessorFactory processorFactory, bool invokeProcessorAfterRecieveTimeout, Action <ExceptionReceivedEventArgs> exceptionHandler, BlobsCheckpointStore checkpointStore) : base(eventBatchMaximumCount, consumerGroup, connectionString, eventHubName, options)
 {
     ProcessorFactory = processorFactory;
     InvokeProcessorAfterRecieveTimeout = invokeProcessorAfterRecieveTimeout;
     ExceptionHandler = exceptionHandler;
     LeaseInfos       = new ConcurrentDictionary <string, LeaseInfo>();
     CheckpointStore  = checkpointStore;
 }
Exemple #7
0
 public async Task StartProcessingAsync(
     IEventProcessorFactory processorFactory,
     BlobsCheckpointStore checkpointStore,
     CancellationToken cancellationToken)
 {
     _processorFactory = processorFactory;
     _checkpointStore  = checkpointStore;
     await StartProcessingAsync(cancellationToken).ConfigureAwait(false);
 }
Exemple #8
0
 public EventReceiver(IEventHubBuilder builder, string eventHubName, string consumerName)
 {
     _builder               = builder;
     _eventHubName          = eventHubName;
     _consumerName          = consumerName;
     _callback              = new EventCallback(EventReceived);
     _eventProcessorHost    = _builder.CreateEventProcessorHost(_eventHubName, _consumerName).Result;
     _eventProcessorFactory = new AzureEventProcessorFactory(Callback);
 }
 public IotHubListener(
     IEventProcessorFactory iotHubEventProcessorFactory,
     IEventProcessorHostConfig eventProcessorHostConfig,
     IOptions <EventProcessorOptions> eventProcessorOptions)
 {
     this.iotHubEventProcessorFactory = iotHubEventProcessorFactory;
     this.eventProcessorHostConfig    = eventProcessorHostConfig;
     this.eventProcessorOptions       = eventProcessorOptions?.Value;
 }
 public EventHubProcessorHost(IEventProcessorFactory eventProcessorFactory, string serviceBusConnectionString,
                              string storageConnectionString, string eventHubName, ILogger logger)
 {
     _eventProcessorFactory      = eventProcessorFactory;
     _serviceBusConnectionString = serviceBusConnectionString;
     _storageConnectionString    = storageConnectionString;
     _eventHubName = eventHubName;
     _logger       = logger;
 }
        public async Task RegisterEventProcessorFactoryAsync(IEventProcessorFactory factory, int maxBatchSize, bool invokeProcessorAfterReceiveTimeout, EventProcessorOptions options)
        {
            if (CurrentProcessor != null)
            {
                throw new InvalidOperationException("Processor has already been started");
            }

            CurrentProcessor = new Processor(maxBatchSize, ConsumerGroupName, EventHubConnectionString, LegacyCheckpointStorageBlobPrefix, EventHubPath, options, factory, invokeProcessorAfterReceiveTimeout, ExceptionHandler, new BlobContainerClient(StorageConnectionString, LeaseContainerName));
            await CurrentProcessor.StartProcessingAsync().ConfigureAwait(false);
        }
Exemple #12
0
 public Agent(ILogger logger,
              IServicesConfig servicesConfig,
              IEventProcessorHostWrapper eventProcessorHostWrapper,
              IEventProcessorFactory actionsEventProcessorFactory)
 {
     this.logger         = logger;
     this.servicesConfig = servicesConfig;
     this.actionsEventProcessorFactory = actionsEventProcessorFactory;
     this.eventProcessorHostWrapper    = eventProcessorHostWrapper;
 }
 /// <summary>
 /// Create host wrapper
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="config"></param>
 /// <param name="logger"></param>
 /// <param name="checkpoint"></param>
 /// <param name="lease"></param>
 public EventProcessorHost(IEventProcessorFactory factory,
                           IEventProcessorConfig config, ICheckpointManager checkpoint,
                           ILeaseManager lease, ILogger logger)
 {
     _logger     = logger ?? throw new ArgumentNullException(nameof(logger));
     _config     = config ?? throw new ArgumentNullException(nameof(config));
     _factory    = factory ?? throw new ArgumentNullException(nameof(factory));
     _lease      = lease;
     _checkpoint = checkpoint;
     _lock       = new SemaphoreSlim(1);
 }
 public EventProcessorWrapper(
     IEventProcessorFactory eventProcessorFactory,
     EventProcessorHostControllerSettings settings)
 {
     _eventProcessorFactory = eventProcessorFactory;
     _processor             = new EventProcessorHost(
         settings.EventHubName,
         settings.ConsumerGroupName,
         settings.EventHubConnectionString,
         settings.StorageConnectionString,
         settings.LeaseContainerName);
 }
        public static async Task <EventProcessorHost> AttachProcessorForHub(
            string processorName,
            string serviceBusConnectionString,
            string offsetStorageConnectionString,
            string eventHubName,
            IEventProcessorFactory processorFactory)
        {
            var eventProcessorHost = new EventProcessorHost(processorName, eventHubName, EventHubConsumerGroup.DefaultGroupName, serviceBusConnectionString, offsetStorageConnectionString);
            await eventProcessorHost.RegisterEventProcessorFactoryAsync(processorFactory);

            return(eventProcessorHost);
        }
Exemple #16
0
        public EventSubscriber(IServiceProvider serviceProvider, string providerName)
        {
            this.providerName           = providerName;
            this._serviceProvider       = serviceProvider;
            this._logger                = this._serviceProvider.GetRequiredService <ILogger <EventSubscriber> >();
            this._options               = serviceProvider.GetRequiredService <IOptionsSnapshot <RabbitOptions> >().Get(providerName);
            this._eventProcessorFactory = serviceProvider.GetRequiredService <IEventProcessorFactory>();
            this._serializer            = this._serviceProvider.GetRequiredServiceByName <ISerializer>(_options.SerializationType);
            var _channelFactory = serviceProvider.GetRequiredServiceByName <IRabbitChannelFactory>(this.providerName);

            this._monitorTimer = new Timer(state => { MonitorConsumer().Wait(); }, null, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
        }
Exemple #17
0
 internal ConfigurationBuilder(Configuration copyFrom)
 {
     _dataSourceFactory           = copyFrom.DataSourceFactory;
     _dataStoreFactory            = copyFrom.DataStoreFactory;
     _diagnosticOptOut            = copyFrom.DiagnosticOptOut;
     _eventProcessorFactory       = copyFrom.EventProcessorFactory;
     _httpConfigurationFactory    = copyFrom.HttpConfigurationFactory;
     _loggingConfigurationFactory = copyFrom.LoggingConfigurationFactory;
     _offline       = copyFrom.Offline;
     _sdkKey        = copyFrom.SdkKey;
     _startWaitTime = copyFrom.StartWaitTime;
 }
Exemple #18
0
 public Agent(
     ILogger logger,
     IConfig config,
     IEventProcessorFactory factory,
     IThroughputCounter throughtCounter,
     IMessages messages)
 {
     this.config           = config;
     this.logger           = logger;
     this.processorFactory = factory;
     this.throughtCounter  = throughtCounter;
     this.messages         = messages;
 }
Exemple #19
0
        public MessageProcessorService(ITelemetryInsightsLogger logger, IEventProcessorFactory factory, EventProcessorHost host)
        {
            _logger  = logger;
            _factory = factory;
            _host    = host;

            _options = new EventProcessorOptions
            {
                MaxBatchSize   = 200,
                PrefetchCount  = 500,
                ReceiveTimeout = TimeSpan.FromMinutes(2),
            };
        }
Exemple #20
0
 internal ConfigurationBuilder(Configuration copyFrom)
 {
     _bigSegmentsConfigurationFactory = copyFrom.BigSegmentsConfigurationFactory;
     _dataSourceFactory           = copyFrom.DataSourceFactory;
     _dataStoreFactory            = copyFrom.DataStoreFactory;
     _diagnosticOptOut            = copyFrom.DiagnosticOptOut;
     _eventProcessorFactory       = copyFrom.EventProcessorFactory;
     _httpConfigurationFactory    = copyFrom.HttpConfigurationFactory;
     _loggingConfigurationFactory = copyFrom.LoggingConfigurationFactory;
     _offline = copyFrom.Offline;
     _sdkKey  = copyFrom.SdkKey;
     _serviceEndpointsBuilder = new ServiceEndpointsBuilder(copyFrom.ServiceEndpoints);
     _startWaitTime           = copyFrom.StartWaitTime;
 }
        public static async Task <EventProcessorHost> AttachProcessorForHub(
            string processorName,
            string eventHubConnection,
            string storageConnection,
            string eventHubName,
            string consumerGroup,
            IEventProcessorFactory factory)
        {
            var eventProcessorHost = new EventProcessorHost(processorName, eventHubName, consumerGroup,
                                                            eventHubConnection, storageConnection);
            await eventProcessorHost.RegisterEventProcessorFactoryAsync(factory);

            return(eventProcessorHost);
        }
Exemple #22
0
        /// <summary>
        /// This registers <see cref="IEventProcessorFactory"/> implementation with the host which is used to create an instance of
        /// <see cref="IEventProcessor"/> when it takes ownership of a partition.  This also starts the host and causes it to start participating
        /// in the partition distribution process.
        /// </summary>
        /// <param name="factory">Instance of <see cref="IEventProcessorFactory"/> implementation.</param>
        /// <param name="processorOptions"><see cref="EventProcessorOptions"/> to control various aspects of message pump created when ownership
        /// is acquired for a particular partition of EventHub.</param>
        /// <returns>A task to indicate EventProcessorHost instance is started.</returns>
        public async Task RegisterEventProcessorFactoryAsync(IEventProcessorFactory factory, EventProcessorOptions processorOptions)
        {
            if (factory == null || processorOptions == null)
            {
                throw new ArgumentNullException(factory == null ? nameof(factory) : nameof(processorOptions));
            }

            // Initialize partition manager options with default values if not already set by the client.
            if (this.PartitionManagerOptions == null)
            {
                // Assign partition manager with default options.
                this.PartitionManagerOptions = new PartitionManagerOptions();
            }

            ProcessorEventSource.Log.EventProcessorHostOpenStart(this.HostName, factory.GetType().ToString());

            try
            {
                // Override operation timeout by receive timeout?
                if (processorOptions.ReceiveTimeout > TimeSpan.MinValue)
                {
                    this.OperationTimeout = processorOptions.ReceiveTimeout;

                    if (this.eventHubConnectionString != null)
                    {
                        var cbs = new EventHubsConnectionStringBuilder(this.eventHubConnectionString)
                        {
                            OperationTimeout = processorOptions.ReceiveTimeout
                        };
                        this.eventHubConnectionString = cbs.ToString();
                    }
                }

                // Initialize lease manager if this is an AzureStorageCheckpointLeaseManager
                (this.LeaseManager as AzureStorageCheckpointLeaseManager)?.Initialize(this);

                this.ProcessorFactory      = factory;
                this.EventProcessorOptions = processorOptions;
                await this.PartitionManager.StartAsync().ConfigureAwait(false);
            }
            catch (Exception e)
            {
                ProcessorEventSource.Log.EventProcessorHostOpenError(this.HostName, e.ToString());
                throw;
            }
            finally
            {
                ProcessorEventSource.Log.EventProcessorHostOpenStop(this.HostName);
            }
        }
 internal ConfigurationBuilder(Configuration copyFrom)
 {
     _autoAliasingOptOut          = copyFrom.AutoAliasingOptOut;
     _dataSourceFactory           = copyFrom.DataSourceFactory;
     _diagnosticOptOut            = copyFrom.DiagnosticOptOut;
     _enableBackgroundUpdating    = copyFrom.EnableBackgroundUpdating;
     _evaluationReasons           = copyFrom.EvaluationReasons;
     _eventProcessorFactory       = copyFrom.EventProcessorFactory;
     _httpConfigurationBuilder    = copyFrom.HttpConfigurationBuilder;
     _loggingConfigurationBuilder = copyFrom.LoggingConfigurationBuilder;
     _mobileKey = copyFrom.MobileKey;
     _offline   = copyFrom.Offline;
     _persistenceConfigurationBuilder = copyFrom.PersistenceConfigurationBuilder;
     _serviceEndpointsBuilder         = new ServiceEndpointsBuilder(copyFrom.ServiceEndpoints);
 }
Exemple #24
0
        public async Task <bool> RegisterEventMessageConsumerAsync(string name, IEventProcessorFactory eventProcessorFactory)
        {
            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();
            }

            await eventProcessorHost.RegisterEventProcessorFactoryAsync(eventProcessorFactory, eventProcessorOptions);

            EventProcessorHostList.Add(eventProcessorHost);
            EventProcessorFactoryList.Add(name, eventProcessorFactory);

            return(true);
        }
        public async Task RegisterEventProcessorFactoryAsync(IEventProcessorFactory factory, int maxBatchSize, bool invokeProcessorAfterReceiveTimeout, BlobsCheckpointStore checkpointStore, EventProcessorOptions options)
        {
            if (CurrentProcessor != null)
            {
                throw new InvalidOperationException("Processor has already been started");
            }

            CurrentProcessor = new Processor(maxBatchSize,
                                             ConsumerGroupName,
                                             EventHubConnectionString,
                                             EventHubName,
                                             options,
                                             factory,
                                             invokeProcessorAfterReceiveTimeout,
                                             ExceptionHandler,
                                             checkpointStore
                                             );
            await CurrentProcessor.StartProcessingAsync().ConfigureAwait(false);
        }
Exemple #26
0
 public Agent(
     IDeviceGroupsWriter deviceGroupsWriter,
     IDeviceGroupsClient deviceGroupsClient,
     IEventProcessorHostWrapper eventProcessorHostWrapper,
     IEventProcessorFactory deviceEventProcessorFactory,
     IEventHubStatus eventHubStatus,
     IServicesConfig servicesConfig,
     IBlobStorageConfig blobStorageConfig,
     ILogger logger,
     IThreadWrapper thread)
 {
     this.log = logger;
     this.deviceGroupsWriter          = deviceGroupsWriter;
     this.deviceGroupsClient          = deviceGroupsClient;
     this.eventProcessorHostWrapper   = eventProcessorHostWrapper;
     this.deviceEventProcessorFactory = deviceEventProcessorFactory;
     this.eventHubStatus    = eventHubStatus;
     this.servicesConfig    = servicesConfig;
     this.blobStorageConfig = blobStorageConfig;
     this.deviceGroupDefinitionDictionary = new Dictionary <string, string>();
     this.thread = thread;
 }
        /// <summary>
        /// This registers <see cref="IEventProcessorFactory"/> implementation with the host which is used to create an instance of
        /// <see cref="IEventProcessor"/> when it takes ownership of a partition.  This also starts the host and causes it to start participating
        /// in the partition distribution process.
        /// </summary>
        /// <param name="factory">Instance of <see cref="IEventProcessorFactory"/> implementation.</param>
        /// <param name="processorOptions"><see cref="EventProcessorOptions"/> to control various aspects of message pump created when ownership
        /// is acquired for a particular partition of EventHub.</param>
        /// <returns>A task to indicate EventProcessorHost instance is started.</returns>
        public async Task RegisterEventProcessorFactoryAsync(IEventProcessorFactory factory, EventProcessorOptions processorOptions)
        {
            if (factory == null || processorOptions == null)
            {
                throw new ArgumentNullException(factory == null ? nameof(factory) : nameof(processorOptions));
            }

            ProcessorEventSource.Log.EventProcessorHostOpenStart(this.Id, factory.GetType().ToString());
            try
            {
                // Override operation timeout by receive timeout?
                if (processorOptions.ReceiveTimeout > TimeSpan.MinValue)
                {
                    var cbs = new EventHubsConnectionStringBuilder(this.EventHubConnectionString)
                    {
                        OperationTimeout = processorOptions.ReceiveTimeout
                    };
                    this.EventHubConnectionString = cbs.ToString();
                }

                if (this.initializeLeaseManager)
                {
                    ((AzureStorageCheckpointLeaseManager)this.LeaseManager).Initialize(this);
                }

                this.ProcessorFactory      = factory;
                this.EventProcessorOptions = processorOptions;
                await this.PartitionManager.StartAsync().ConfigureAwait(false);
            }
            catch (Exception e)
            {
                ProcessorEventSource.Log.EventProcessorHostOpenError(this.Id, e.ToString());
                throw;
            }
            finally
            {
                ProcessorEventSource.Log.EventProcessorHostOpenStop(this.Id);
            }
        }
        public LdClient(Configuration config, IEventProcessor eventProcessor)
        {
            Log.InfoFormat("Starting LaunchDarkly Client {0}",
                           ServerSideClientEnvironment.Instance.Version);

            _configuration = config;
            ServerDiagnosticStore diagnosticStore = null;

            if (!_configuration.DiagnosticOptOut)
            {
                diagnosticStore = new ServerDiagnosticStore(_configuration);
            }

            if (eventProcessor == null)
            {
                IEventProcessorFactory eventProcessorFactory = _configuration.EventProcessorFactory ?? Components.DefaultEventProcessor;
                if (eventProcessorFactory is IEventProcessorFactoryWithDiagnostics epfwd)
                {
                    _eventProcessor = epfwd.CreateEventProcessor(_configuration, diagnosticStore);
                }
                else
                {
                    _eventProcessor = eventProcessorFactory.CreateEventProcessor(_configuration);
                }
                _shouldDisposeEventProcessor = true;
            }
            else
            {
                _eventProcessor = eventProcessor;
                // The following line is for backward compatibility with the obsolete mechanism by which the
                // caller could pass in an IStoreEvents implementation instance that we did not create.  We
                // were not disposing of that instance when the client was closed, so we should continue not
                // doing so until the next major version eliminates that mechanism.  We will always dispose
                // of instances that we created ourselves from a factory.
                _shouldDisposeEventProcessor = false;
            }

            IFeatureStore store;

            if (_configuration.FeatureStore == null)
            {
                store = (_configuration.FeatureStoreFactory ??
                         Components.InMemoryFeatureStore).CreateFeatureStore();
                _shouldDisposeFeatureStore = true;
            }
            else
            {
                store = _configuration.FeatureStore;
                _shouldDisposeFeatureStore = false; // see previous comment
            }
            _featureStore = new FeatureStoreClientWrapper(store);

            IUpdateProcessorFactory updateProcessorFactory = _configuration.UpdateProcessorFactory ?? Components.DefaultUpdateProcessor;

            if (updateProcessorFactory is IUpdateProcessorFactoryWithDiagnostics upfwd)
            {
                _updateProcessor = upfwd.CreateUpdateProcessor(_configuration, _featureStore, diagnosticStore);
            }
            else
            {
                _updateProcessor = updateProcessorFactory.CreateUpdateProcessor(_configuration, _featureStore);
            }

            var initTask = _updateProcessor.Start();

            if (!(_updateProcessor is NullUpdateProcessor))
            {
                Log.InfoFormat("Waiting up to {0} milliseconds for LaunchDarkly client to start..",
                               _configuration.StartWaitTime.TotalMilliseconds);
            }

            try
            {
                var unused = initTask.Wait(_configuration.StartWaitTime);
            }
            catch (AggregateException)
            {
                // StreamProcessor may throw an exception if initialization fails, because we want that behavior
                // in the Xamarin client. However, for backward compatibility we do not want to throw exceptions
                // from the LdClient constructor in the .NET client, so we'll just swallow this.
            }
        }
Exemple #29
0
 /// <summary>
 /// Create host wrapper
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="hub"></param>
 /// <param name="config"></param>
 /// <param name="logger"></param>
 public EventProcessorHost(IEventProcessorFactory factory, IEventHubConsumerConfig hub,
                           IEventProcessorConfig config, ILogger logger) :
     this(factory, hub, config, null, null, logger)
 {
 }
Exemple #30
0
        public virtual async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            var       eventDataList = new List <EventData>();
            EventData lastEventData = null;

            if (ConsumerConfiguration.ConsumeDelayInSeconds == null)
            {
                lastEventData = messages.LastOrDefault();
                eventDataList = messages.ToList();
            }
            else
            {
                foreach (var eventData in messages)
                {
                    if (ConsumerConfiguration.ConsumeDelayInSeconds != null && eventData.SystemProperties.EnqueuedTimeUtc <= DateTime.UtcNow.AddSeconds(ConsumerConfiguration.ConsumeDelayInSeconds.Value * (-1)))
                    {
                        lastEventData = eventData;
                        eventDataList.Add(eventData);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (lastEventData != null)
            {
                try
                {
                    bool sucess = await ProcessEventDataList(context, eventDataList);

                    if (sucess)
                    {
                        await context.CheckpointAsync(lastEventData);
                    }
                    else if (!sucess && !string.IsNullOrWhiteSpace(ConsumerConfiguration.ProducerName))
                    {
                        var sendToShuntList = new List <EventData>();
                        var sendToRetryList = new List <EventData>();
                        IEventHubProducerService eventHubProducerService = ServiceProvider.GetService <IEventHubProducerService>();

                        foreach (var eventData in eventDataList)
                        {
                            if (eventData.HasIsOkProperty())
                            {
                                eventData.RemoveSendToShuntProperty().RemoveIsOkProperty().RemoveRetryProperty();
                                continue;
                            }

                            int incrementedRetryProperty = eventData.IncrementRetryProperty();
                            if (!string.IsNullOrWhiteSpace(ConsumerConfiguration.Shunt?.ProducerName) &&
                                (eventData.HasSendToShuntProperty() ||
                                 (ConsumerConfiguration.Shunt.MaxRetry > 0 && incrementedRetryProperty > ConsumerConfiguration.Shunt.MaxRetry))
                                )
                            {
                                eventData.RemoveSendToShuntProperty().RemoveIsOkProperty().RemoveRetryProperty();
                                sendToShuntList.Add(eventData);
                            }
                            else
                            {
                                sendToRetryList.Add(eventData);
                            }
                        }
                        if (sendToShuntList.Any())
                        {
                            await eventHubProducerService.SendEventDataAsync(ConsumerConfiguration.Shunt.ProducerName, sendToShuntList);
                        }
                        if (sendToRetryList.Any())
                        {
                            await eventHubProducerService.SendEventDataAsync(ConsumerConfiguration.ProducerName, sendToRetryList);
                        }

                        await context.CheckpointAsync(lastEventData);
                    }
                }
                catch (Exception ex)
                {
                    IEventProcessorFactory eventProcessorFactory = null;

                    try
                    {
                        await Task.Run(() =>
                                       new ExecuteAsync(1, 1000, async() =>
                        {
                            IEventHubConsumerService eventHubConsumerService = ServiceProvider.GetService <IEventHubConsumerService>();

                            eventProcessorFactory = await eventHubConsumerService.UnregisterEventMessageConsumerAsync(ConsumerConfiguration.Name);

                            Thread.Sleep(10000);

                            await eventHubConsumerService.RegisterEventMessageConsumerAsync(ConsumerConfiguration.Name, eventProcessorFactory);
                        }).Do(true));
                    }
                    catch (Exception ex2)
                    {
                        if (ServiceProvider != null)
                        {
                            IEventHubConsumerService eventHubConsumerService = ServiceProvider.GetService <IEventHubConsumerService>();

                            if (eventProcessorFactory != null)
                            {
                                await eventHubConsumerService.RegisterEventMessageConsumerAsync(ConsumerConfiguration.Name, eventProcessorFactory);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Sets the implementation of <see cref="IEventProcessor"/> to be used for processing analytics events,
 /// using a factory object. The default is <see cref="Components.DefaultEventProcessor"/>, but
 /// you may choose to use a custom implementation (for instance, a test fixture).
 /// </summary>
 /// <param name="configuration">the configuration</param>
 /// <param name="factory">the factory object</param>
 /// <returns>the same <c>Configuration</c> instance</returns>
 public static Configuration WithEventProcessorFactory(this Configuration configuration, IEventProcessorFactory factory)
 {
     configuration.EventProcessorFactory = factory;
     return(configuration);
 }
 public SimpleEventHubHost(ICreateClients clientFactory) : base(clientFactory)
 {
     _processorFactory = new SimpleProcessorFactory();
 }
 public DeliveryWebService(IProfileService profileService, IEventProcessorFactory eventProcessorFactory, IMappingEngine mappingEngine)
 {
     _profileService = profileService;
     _eventProcessorFactory = eventProcessorFactory;
     _mappingEngine = mappingEngine;
 }