private NotificationMetadata(string ioTHubName, string deviceId, NotificationMessageSchemas messageSchema, string rawMessageSchema, string correlationId) { Guard.NotNullOrWhitespace(ioTHubName, nameof(ioTHubName)); Guard.NotNullOrWhitespace(deviceId, nameof(deviceId)); IoTHubName = ioTHubName; DeviceId = deviceId; MessageSchema = messageSchema; RawMessageSchema = rawMessageSchema; CorrelationId = correlationId; }
public async Task ProcessAsync(NotificationMessageSchemas messageSchema, NotificationMetadata notificationMetadata, string rawMessage) { IEventProcessor processor; switch (messageSchema) { case NotificationMessageSchemas.TwinChangeNotification: processor = _serviceProvider.GetRequiredService <TwinChangedNotificationProcessor>(); break; default: _logger.LogWarning("Message schema {MessageSchema} is not supported and being ignored", notificationMetadata.RawMessageSchema); return; } await processor.ProcessAsync(notificationMetadata, rawMessage); }
public static NotificationMetadata Parse(EventData eventData) { Guard.NotNull(eventData, nameof(eventData)); var deviceId = eventData.Properties[EventProperties.DeviceId]?.ToString(); var ioTHubName = eventData.Properties[EventProperties.IoTHubName]?.ToString(); var rawMessageSchema = eventData.Properties[EventProperties.MessageSchema]?.ToString(); var correlationId = eventData.SystemProperties[EventSystemProperties.CorrelationId].ToString(); NotificationMessageSchemas messageSchema = NotificationMessageSchemas.Unknown; if (Enum.TryParse(rawMessageSchema, ignoreCase: true, out NotificationMessageSchemas parsedSchema)) { messageSchema = parsedSchema; } return(new NotificationMetadata(ioTHubName, deviceId, messageSchema, rawMessageSchema, correlationId)); }