public override bool OnStart() { try { // Register the dependency resolver for initializing handlers and service // classes. var resolver = CarWorkerHostDependencyResolver.CreateAsync().Result; DependencyResolverFactory.Register( resolver ); // Set up the process defaults for connections to optimize storage performance ServicePointManager.DefaultConnectionLimit = int.MaxValue; var configuration = DispatcherConfiguration.GetCurrentConfiguration(); var typesToSearchForHandlers = typeof(UpdateLocationHandler) .Assembly .DefinedTypes; _coordinator = ProcessingCoordinator.CreateAsync( RoleEnvironment.CurrentRoleInstance.Id, configuration.EventHubName, configuration.ConsumerGroupName, configuration.EventHubConnectionString, configuration.CheckpointStorageAccount, configuration.MaxBatchSize, configuration.PrefetchCount, configuration.ReceiveTimeout, configuration.MaxConcurrencyPerProcessor, typesToSearchForHandlers, (name, partitionId) => new CircuitBreaker( name, partitionId, configuration.CircuitBreakerWarningLevel, configuration.CircuitBreakerTripLevel, configuration.CircuitBreakerStallInterval, configuration.CircuitBreakerLogCooldownInterval), new DispatcherInstrumentationManager(instrumentationEnabled: true).CreatePublisher("WaWorkerHost")).Result; bool result = base.OnStart(); return result; } catch (Exception ex) { // Hard error on startup, usually configuration or security related // Ensure that we log this error, including a direct post to the local // event log LogHelpers.HandleRoleException(Logger, "OnStart()", ex); Trace.TraceError(ex.ToString()); throw; } }
/// <summary> /// /// </summary> /// <param name="hostName">The name of the host, most like a worker role.</param> /// <param name="eventHubName">The name of the event hub.</param> /// <param name="consumerGroupName">The name of the consumer group.</param> /// <param name="eventHubConnectionString">The connection string from the event hub.</param> /// <param name="checkpointStorageAccount">The connection string for the storage account used when checkpointing for the event hub.</param> /// <param name="maxBatchSize">The maximum size of the batch of events that the event processor will receive.</param> /// <param name="prefetchCount">The number of events that the underlying event hub client will attempt to prefetch.</param> /// <param name="receiveTimeout">The length of time the event processor host will wait before invoking ProcessEventsAsync when no events have been received.</param> /// <param name="maxConcurrencyPerProcessor">The number of events a single event processor will process concurrently.</param> /// <param name="typesToSearch">The collection of types to search for registered event handlers.</param> /// <param name="circuitBreakerFactory">Factory function for creating a the circuit breaker.</param> /// <param name="instrumentationPublisher">Used for custom performance counters.</param> /// <returns></returns> public async static Task<ProcessingCoordinator> CreateAsync( 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) { var mp = new ProcessingCoordinator(); await mp.InitializeAsync( hostName, eventHubName, consumerGroupName, eventHubConnectionString, checkpointStorageAccount, maxBatchSize, prefetchCount, receiveTimeout, maxConcurrencyPerProcessor, typesToSearch, circuitBreakerFactory, instrumentationPublisher); return mp; }
/// <summary> /// /// </summary> /// <param name="hostName">The name of the host, most like a worker role.</param> /// <param name="eventHubName">The name of the event hub.</param> /// <param name="consumerGroupName">The name of the consumer group.</param> /// <param name="eventHubConnectionString">The connection string from the event hub.</param> /// <param name="checkpointStorageAccount">The connection string for the storage account used when checkpointing for the event hub.</param> /// <param name="maxBatchSize">The maximum size of the batch of events that the event processor will receive.</param> /// <param name="prefetchCount">The number of events that the underlying event hub client will attempt to prefetch.</param> /// <param name="receiveTimeout">The length of time the event processor host will wait before invoking ProcessEventsAsync when no events have been received.</param> /// <param name="maxConcurrencyPerProcessor">The number of events a single event processor will process concurrently.</param> /// <param name="typesToSearch">The collection of types to search for registered event handlers.</param> /// <param name="circuitBreakerFactory">Factory function for creating a the circuit breaker.</param> /// <param name="instrumentationPublisher">Used for custom performance counters.</param> /// <returns></returns> public async static Task <ProcessingCoordinator> CreateAsync( 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) { var mp = new ProcessingCoordinator(); await mp.InitializeAsync( hostName, eventHubName, consumerGroupName, eventHubConnectionString, checkpointStorageAccount, maxBatchSize, prefetchCount, receiveTimeout, maxConcurrencyPerProcessor, typesToSearch, circuitBreakerFactory, instrumentationPublisher); return(mp); }