Exemple #1
0
        public static async Task Main()
        {
            var config       = GetEnvironmentConfig();
            var eventHubName = GetEventHubName(config);

            var eventHubOptions = GetEventHubInfo(config, eventHubName);

            EnsureArg.IsNotNullOrWhiteSpace(eventHubOptions.EventHubConnectionString);
            EnsureArg.IsNotNullOrWhiteSpace(eventHubOptions.EventHubName);

            var serviceCollection = GetRequiredServiceCollection(config, eventHubName);
            var serviceProvider   = serviceCollection.BuildServiceProvider();

            var logger = serviceProvider.GetRequiredService <ITelemetryLogger>();

            var blobContainerClientFactory = new BlobContainerClientFactory();
            var eventConsumers             = GetEventConsumers(config, eventHubName, serviceProvider, blobContainerClientFactory, logger);

            var storageOptions = new StorageCheckpointOptions();

            config.GetSection(StorageCheckpointOptions.Settings).Bind(storageOptions);
            var checkpointContainerOptions = new BlobContainerClientOptions();

            config.GetSection("CheckpointStorage").Bind(checkpointContainerOptions);

            var storageCheckpointClient = GetStorageCheckpointClient(blobContainerClientFactory, checkpointContainerOptions, storageOptions, logger, eventHubName);
            var eventConsumerService    = new EventConsumerService(eventConsumers, logger);

            var incomingEventReader = GetEventProcessorClient(storageCheckpointClient.GetBlobContainerClient(), eventHubOptions);
            var eventHubReader      = GetEventProcessor(config, eventConsumerService, storageCheckpointClient, logger);

            System.Console.WriteLine($"Reading from event hub: {eventHubName}");
            var ct = new CancellationToken();
            await eventHubReader.RunAsync(incomingEventReader, ct);
        }
Exemple #2
0
        public static StorageCheckpointClient GetStorageCheckpointClient(BlobContainerClientFactory factory, BlobContainerClientOptions containerOptions, StorageCheckpointOptions options, ITelemetryLogger logger, string prefix)
        {
            var checkpointBlobClient = factory.CreateStorageClient(containerOptions);

            options.BlobPrefix = prefix;
            var checkpointClient = new StorageCheckpointClient(checkpointBlobClient, options, logger);

            return(checkpointClient);
        }
Exemple #3
0
        public static TemplateManager GetMappingTemplateManager(IConfiguration config, BlobContainerClientFactory blobClientFactory)
        {
            var containerOptions = new BlobContainerClientOptions();

            config.GetSection("TemplateStorage").Bind(containerOptions);
            var containerClient = blobClientFactory.CreateStorageClient(containerOptions);
            var storageManager  = new StorageManager(containerClient);
            var templateManager = new TemplateManager(storageManager);

            return(templateManager);
        }
Exemple #4
0
        public static List <IEventConsumer> GetEventConsumers(IConfiguration config, string inputEventHub, ServiceProvider sp, BlobContainerClientFactory blobClientFactory, ITelemetryLogger logger)
        {
            var eventConsumers = new List <IEventConsumer>();

            var templateManager = GetMappingTemplateManager(config, blobClientFactory);

            if (inputEventHub == "devicedata")
            {
                var template = config.GetSection("Template:DeviceContent").Value;
                var deviceDataNormalization = new Normalize.Processor(template, templateManager, config, sp.GetRequiredService <IOptions <EventHubMeasurementCollectorOptions> >(), logger);
                eventConsumers.Add(deviceDataNormalization);
            }

            else if (inputEventHub == "normalizeddata")
            {
                var template = config.GetSection("Template:FhirMapping").Value;
                var measurementImportService  = ResolveMeasurementService(sp);
                var measurementToFhirConsumer = new MeasurementCollectionToFhir.Processor(template, templateManager, measurementImportService, logger);
                eventConsumers.Add(measurementToFhirConsumer);
            }

            if (config.GetSection("Console:Debug")?.Value == "true")
            {
                eventConsumers.Add(new EventPrinter());
            }

            return(eventConsumers);
        }