예제 #1
0
        /// <summary>
        /// Method to handle messages coming from a leaf device corresponds with route
        /// "FROM /messages/* WHERE NOT IS_DEFINED($connectionModuleId) INTO BrokeredEndpoint(\"/modules/turbofanRouter/inputs/deviceInput\")"
        /// </summary>
        internal static async Task <MessageResponse> LeafDeviceInputMessageHandler(Message message, object userContext)
        {
            int counterValue = Interlocked.Increment(ref deviceMessageCounter);

            Logger.Log($"Received message on {EndpointNames.FromLeafDevice}; Count: {counterValue}");

            try
            {
                var fanMessage   = new TurbofanMessage(message);
                var moduleClient = GetClientFromContext(userContext);

                if (fanMessage.HasRemainingRul)
                {
                    Logger.Log($"Endpoint {EndpointNames.FromLeafDevice}: already classified, stop processing.", LogSeverity.Warning);
                    return(await HandleBadMessage(message, moduleClient).ConfigureAwait(false));
                }

                await SendMessageToClassifier(moduleClient, fanMessage).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.Log($"LeafDeviceInputMessageHandler got exception {ex.Message}", LogSeverity.Error);
            }

            return(MessageResponse.Completed);
        }
예제 #2
0
        private static async Task SendMessageToAvroWriter(ModuleClient moduleClient, TurbofanMessage fanMessage)
        {
            Message avroMessage = fanMessage.CreateAvroWriterMessage();
            await moduleClient
            .SendEventAsync(EndpointNames.ToAvroWriter, avroMessage)
            .ConfigureAwait(false);

            Logger.Log($"Sent avro message to {EndpointNames.ToAvroWriter} for DeviceId: {fanMessage.DeviceId} CycleTime: {fanMessage.Message["CycleTime"]}");
        }
예제 #3
0
        private static async Task SendRulMessageToIotHub(ModuleClient moduleClient, TurbofanMessage fanMessage)
        {
            Message rulMessage = fanMessage.CreateRemainingLifeMessage();
            await moduleClient
            .SendEventAsync(EndpointNames.ToIotHub, rulMessage)
            .ConfigureAwait(false);

            Logger.Log($"Sent rul message to {EndpointNames.ToIotHub} for DeviceId: {fanMessage.DeviceId} CycleTime: {fanMessage.Message["CycleTime"]}");
        }
예제 #4
0
        private static async Task SendMessageToClassifier(ModuleClient moduleClient, TurbofanMessage fanMessage)
        {
            Message classifierMessage = fanMessage.CreateClassifierMessage();
            await moduleClient
            .SendEventAsync(EndpointNames.ToClassifierModule, classifierMessage)
            .ConfigureAwait(false);

            Logger.Log($"Sent message to classifier on {EndpointNames.ToClassifierModule} for DeviceId: {fanMessage.DeviceId} CycleTime: {fanMessage.Message["CycleTime"]}");
        }
예제 #5
0
        /// <summary>
        /// Handles messages coming back from the classifier corresponds with route
        /// "FROM /messages/modules/classifier/outputs/amloutput INTO BrokeredEndpoint(\"/modules/turbofanRouter/inputs/rulInput\")"
        /// </summary>
        internal static async Task <MessageResponse> ClassifierCallbackMessageHandler(Message message, object userContext)
        {
            int counterValue = Interlocked.Increment(ref classifierCallbackCounter);

            Logger.Log($"Received message on {EndpointNames.FromClassifier}; Count: {counterValue}");

            var moduleClient = GetClientFromContext(userContext);
            var fanMessage   = new TurbofanMessage(message);

            if (!fanMessage.HasRemainingRul)
            {
                Logger.Log($"Endpoint {EndpointNames.FromClassifier}: not classified, stop processing", LogSeverity.Error);
                return(await HandleBadMessage(message, moduleClient).ConfigureAwait(false));
            }

            await SendRulMessageToIotHub(moduleClient, fanMessage).ConfigureAwait(false);

            await SendMessageToAvroWriter(moduleClient, fanMessage).ConfigureAwait(false);

            return(MessageResponse.Completed);
        }