Exemple #1
0
        public async Task ConsumeAsync(IEnumerable <IEventMessage> events)
        {
            EnsureArg.IsNotNull(_templateDefinition);
            var templateContent = _templateManager.GetTemplateAsString(_templateDefinition);

            var templateContext = CollectionContentTemplateFactory.Default.Create(templateContent);

            templateContext.EnsureValid();
            var template = templateContext.Template;

            _logger.LogMetric(
                IomtMetrics.DeviceEvent(),
                events.Count());

            IEnumerable <EventData> eventHubEvents = events
                                                     .Select(x =>
            {
                var eventData = new EventData(x.Body.ToArray());

                eventData.SystemProperties = new SystemPropertiesCollection(
                    x.SequenceNumber,
                    x.EnqueuedTime.UtcDateTime,
                    x.Offset.ToString(),
                    x.PartitionId);

                foreach (KeyValuePair <string, object> entry in x.Properties)
                {
                    eventData.Properties[entry.Key] = entry.Value;
                }

                foreach (KeyValuePair <string, object> entry in x.SystemProperties)
                {
                    eventData.SystemProperties.TryAdd(entry.Key, entry.Value);
                }

                return(eventData);
            });

            var dataNormalizationService = new MeasurementEventNormalizationService(_logger, template);
            await dataNormalizationService.ProcessAsync(eventHubEvents, _collector).ConfigureAwait(false);

            if (_normalizationOptions.Value.LogDeviceIngressSizeBytes)
            {
                var eventStats = await _eventProcessingMeter.CalculateEventStats(eventHubEvents);

                _logger.LogMetric(
                    IomtMetrics.DeviceIngressSizeBytes(),
                    eventStats.TotalEventsProcessedBytes);
            }
        }
Exemple #2
0
        private async Task ConsumeAsyncImpl(IEnumerable <IEventMessage> events, string templateContent)
        {
            var templateContext = _collectionTemplateFactory.Create(templateContent);

            templateContext.EnsureValid();
            var template = templateContext.Template;

            _logger.LogMetric(
                IomtMetrics.DeviceEvent(events.FirstOrDefault()?.PartitionId),
                events.Count());

            IEnumerable <EventData> eventHubEvents = events
                                                     .Select(x =>
            {
                var eventData = new EventData(x.Body.ToArray());

                eventData.SystemProperties = new SystemPropertiesCollection(
                    x.SequenceNumber,
                    x.EnqueuedTime.UtcDateTime,
                    x.Offset.ToString(),
                    x.PartitionId);

                if (x.Properties != null)
                {
                    foreach (KeyValuePair <string, object> entry in x.Properties)
                    {
                        eventData.Properties[entry.Key] = entry.Value;
                    }
                }

                if (x.SystemProperties != null)
                {
                    foreach (KeyValuePair <string, object> entry in x.SystemProperties)
                    {
                        eventData.SystemProperties.TryAdd(entry.Key, entry.Value);
                    }
                }

                return(eventData);
            });

            var dataNormalizationService = new MeasurementEventNormalizationService(_logger, template, _exceptionTelemetryProcessor);
            await dataNormalizationService.ProcessAsync(eventHubEvents, _collector).ConfigureAwait(false);
        }
Exemple #3
0
        public async Task ConsumeAsync(IEnumerable <IEventMessage> events)
        {
            EnsureArg.IsNotNull(_templateDefinition);
            var templateContent = _templateManager.GetTemplateAsString(_templateDefinition);

            var templateContext = CollectionContentTemplateFactory.Default.Create(templateContent);

            templateContext.EnsureValid();
            var template = templateContext.Template;

            _logger.LogMetric(
                IomtMetrics.DeviceEvent(),
                events.Count());

            IEnumerable <EventData> eventHubEvents = events
                                                     .Select(x =>
            {
                var eventData = new EventData(x.Body.ToArray());
                eventData.SystemProperties = new SystemPropertiesCollection(
                    x.SequenceNumber,
                    x.EnqueuedTime.UtcDateTime,
                    x.Offset.ToString(),
                    x.PartitionId);

                foreach (KeyValuePair <string, object> entry in x.SystemProperties)
                {
                    eventData.SystemProperties.TryAdd(entry.Key, entry.Value);
                }

                return(eventData);
            });

            var dataNormalizationService = new MeasurementEventNormalizationService(_logger, template);

            // todo: support managed identity
            var connectionString = _env.GetSection("OutputEventHub").Value;
            var sb           = new EventHubsConnectionStringBuilder(connectionString);
            var eventHubName = sb.EntityPath;

            var collector = CreateCollector(eventHubName, connectionString, _options);

            await dataNormalizationService.ProcessAsync(eventHubEvents, collector).ConfigureAwait(false);
        }