Exemple #1
0
        public static async Task <WarmStorageCoordinator> CreateAsync(string hostName, Configuration configuration)
        {
            WarmStorageEventSource.Log.InitializingEventHubListener(configuration.EventHubName, configuration.ConsumerGroupName);

            Func <string, IElasticSearchWriter> elasticSearchWriterFactory = partitionId =>
                                                                             new ElasticSearchWriter.ElasticSearchWriter(
                configuration.ElasticSearchUrl,
                configuration.ElasticSearchIndexPrefix,
                configuration.ElasticSearchIndexType,
                configuration.RetryCount
                );

            var ns = NamespaceManager.CreateFromConnectionString(configuration.EventHubConnectionString);

            try
            {
                await ns.GetConsumerGroupAsync(configuration.EventHubName, configuration.ConsumerGroupName);
            }
            catch (Exception e)
            {
                WarmStorageEventSource.Log.InvalidEventHubConsumerGroupName(e, configuration.EventHubName, configuration.ConsumerGroupName);
                throw;
            }

            WarmStorageEventSource.Log.ConsumerGroupFound(configuration.EventHubName, configuration.ConsumerGroupName);

            var eventHubId = ConfigurationHelper.GetEventHubName(ns.Address, configuration.EventHubName);

            var buildingLookupService = new BuildingLookupService();
            await buildingLookupService.InitializeAsync();

            var factory = new WarmStorageEventProcessorFactory(elasticSearchWriterFactory, eventHubId, buildingLookupService);

            var options = new EventProcessorOptions()
            {
                MaxBatchSize   = configuration.MaxBatchSize,
                PrefetchCount  = configuration.PreFetchCount,
                ReceiveTimeOut = configuration.ReceiveTimeout
            };

            options.ExceptionReceived +=
                (s, e) => WarmStorageEventSource.Log.ErrorProcessingMessage(e.Exception, e.Action);

            var host = new EventProcessorHost(
                hostName,
                consumerGroupName: configuration.ConsumerGroupName,
                eventHubPath: configuration.EventHubName,
                eventHubConnectionString: configuration.EventHubConnectionString,
                storageConnectionString: configuration.CheckpointStorageAccount);

            await host.RegisterEventProcessorFactoryAsync(factory, options);

            return(new WarmStorageCoordinator(host));
        }
        public static async Task<WarmStorageCoordinator> CreateAsync(string hostName, Configuration configuration)
        {
            WarmStorageEventSource.Log.InitializingEventHubListener(configuration.EventHubName, configuration.ConsumerGroupName);

            Func<string, IElasticSearchWriter> elasticSearchWriterFactory = partitionId => 
                new ElasticSearchWriter.ElasticSearchWriter(
                    configuration.ElasticSearchUrl,
                    configuration.ElasticSearchIndexPrefix,
                    configuration.ElasticSearchIndexType,
                    configuration.RetryCount
                );

            var ns = NamespaceManager.CreateFromConnectionString(configuration.EventHubConnectionString);
            try
            {
                await ns.GetConsumerGroupAsync(configuration.EventHubName, configuration.ConsumerGroupName);
            }
            catch (Exception e)
            {
                WarmStorageEventSource.Log.InvalidEventHubConsumerGroupName(e, configuration.EventHubName, configuration.ConsumerGroupName);
                throw;
            }

            WarmStorageEventSource.Log.ConsumerGroupFound(configuration.EventHubName, configuration.ConsumerGroupName);

            var eventHubId = ConfigurationHelper.GetEventHubName(ns.Address, configuration.EventHubName);

            var buildingLookupService = new BuildingLookupService();
            await buildingLookupService.InitializeAsync();

            var factory = new WarmStorageEventProcessorFactory(elasticSearchWriterFactory, eventHubId, buildingLookupService);

            var options = new EventProcessorOptions()
            {
                MaxBatchSize = configuration.MaxBatchSize,
                PrefetchCount = configuration.PreFetchCount,
                ReceiveTimeOut = configuration.ReceiveTimeout
            };

            options.ExceptionReceived += 
                (s, e) => WarmStorageEventSource.Log.ErrorProcessingMessage(e.Exception, e.Action);

            var host = new EventProcessorHost(
                hostName,
                consumerGroupName: configuration.ConsumerGroupName,
                eventHubPath: configuration.EventHubName,
                eventHubConnectionString: configuration.EventHubConnectionString,
                storageConnectionString: configuration.CheckpointStorageAccount);

            await host.RegisterEventProcessorFactoryAsync(factory, options);

            return new WarmStorageCoordinator(host);
        }