When sending telemetry messages from a device to the following MQTT topic:
devices/<MY_DEVICE>/messages/events/%24.uid=<MY_UID>&%24.ct=application%2Fjson&%24.ce=utf-8&%24.ctime=<SOME_TIME>
With actual values for <...>
and routing them to a service bus topic I can retrieve them using the Azure Python SDK which spits out instances of azure.servicebus.ServiceBusReceivedMessage
(see the documentation).
These object contain most of the information I’m interested in, e.g. content_type
is correctly set to "application/json"
and application_properties
contains iothub-connection-device-id
and iothub-creation-time-utc
. However there seems to be no way to access:
user-id
content-encoding
- Something like
iothub-message-source
that indicates that this is a telemetry message.
This seems very strange to me, if this is not possible in general that would mean a backend application had no way of knowing what IoT Hub a telemetry message comes from, how it is encoded or that it is telemetry at all (and not say, a device twin change message), making the SDK almost useless.
Is there information I am missing?
2
Answers
Unfortunately, the Azure Python SDK currently lacks direct access to some essential properties like user-id, content-encoding, and iothub-message-source, which can be crucial for identifying telemetry messages and their sources accurately. This limitation can indeed pose challenges for backend applications in distinguishing between different types of messages and their origins. You may want to explore alternative approaches or contact Azure support for any updates on this matter.
The available system properties for routing configuration are listed here in MSDOC .
Below are the message properties which are triggered in linked service bus from IoT hub.
Note: Refer MSDOC to check the available service bus message properties.
For
contentEncoding
, the user specifies the encoding type of the message. If thecontentType
property is set toapplication/JSON
, then allowed values areUTF-8
,UTF-16
, andUTF-32
.The
user-id
is user-settable and is the name of the IoT Hub that generated the event.I tried to send/route the data to Event Hub, and according to this document
Note:
By referring to this MSDOC ,I tried to receive events using Azure Event Hubs as shown below.
Event From Iot Hub:
Event from Event Hubs: