/// <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); } }
/// <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); } }