I'm facing an issue with Azure IoT Hub when routing device-to-cloud (D2C) messages to a custom Event Hub, specifically related to system properties within the JSON payload. Normally, when messages are sent to the default Event Hub, the JSON structure includes an IoTHub object containing system properties, which are essential for processing in Stream Analytics. Here's an example of a typical message structure received:
However, when I route the same device message to a dedicated Event Hub (using a routing query based on tag values of the device twin), the IoTHub object is absent in the received JSON payload, as seen below:
I can't find any configuration setting in either IoT Hub or the Event Hub for including this data when setting up the new route. Does anyone know why this discrepancy is occurring, and is there a way to ensure these system properties are included when routing to a non-default Event Hub endpoint?
The System Properties and Application Properties of the D2C IoT Hub messages are described here.
The Azure IoT Hub doesn't have a built-in capability to transform a payload of the iot messages.
I do recommend using on the ASA side a function GetMetadataPropertyValue to obtain the System and/or Application Properties of the iot D2C message, see more details here.
Update:
I have created an EventHub custom endpoint for message routing with two consumer groups such as for Azure function and other one for ASA job:
SELECT
GetMetadataPropertyValue(rk2018eh2, '[EventHub]') AS myEHSystemPropertiesRecord,
GetMetadataPropertyValue(rk2018eh2, '[User]') AS myEHUserPropertiesRecord
INTO outBlob
FROM rk2018eh2
The following screen snippets show their outputs:
Function:
Blob:
As you can see the above outputs, there are both properties such as System and Application in the payload of the iot d2c message.