Forum Discussion
What's the best way for an external application to read data from IoT Hub?
Hi everyone!
I have been studying integration between IoT Hub to external applications and the available endpoints and SDKs.
AFAIK, the current suitable way to externally read telemetry data from IoT Hub is through the https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-endpoints. Besides that, the example I found use it. Like this one: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-live-data-visualization-in-web-apps
But, for this purpose, one would use the Event Hub SDK. See https://docs.microsoft.com/en-us/javascript/api/@azure/event-hubs/eventhubconsumerclient?view=azure-node-latest.
I was wondering if we couldn't do the same using the https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-sdks#azure-iot-hub-service-sdks.
From the Git Hub repository, I can only see C2D messaging support, but taking a deeper look at https://docs.microsoft.com/en-us/javascript/api/azure-iothub/servicereceiver?view=azure-node-latest I thought that maybe this is an alternative.
Does anyone has some info to share about this?
Pros, cons? If my understanding is right?
- Hi Sara
What I would suggest is to consider how you want to read telemetry based on the type of data you want and how and where it will be consumed. IoT Hub allows to route telemetry data to different types of endpoints (Event Hub, Message Bus topics or queues, Azure Storage) which might be more suited for consumption by apps than the built-in Event Hub compatible endpoint based on your scenario and needs. Read more about his here: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-d2c
You can also leverage the integration with Events Grid which offers an events model (rather than messages model): https://docs.microsoft.com/azure/iot-hub/iot-hub-event-grid-routing-comparison
At the end of the day there is no good or bad way of consuming data coming from devices through IoT Hub.
Note that the Service SDKs for IoT Hub are designed to manage the instance of IoT Hub and manage the attached devices (provisioning, Twins, Direct Methods), but do not support telemetry (D2C) consumption because of exactly this (there is not a single way to consume messages/events from devices).
2 Replies
- OlivierBlochIron ContributorHi Sara
What I would suggest is to consider how you want to read telemetry based on the type of data you want and how and where it will be consumed. IoT Hub allows to route telemetry data to different types of endpoints (Event Hub, Message Bus topics or queues, Azure Storage) which might be more suited for consumption by apps than the built-in Event Hub compatible endpoint based on your scenario and needs. Read more about his here: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-d2c
You can also leverage the integration with Events Grid which offers an events model (rather than messages model): https://docs.microsoft.com/azure/iot-hub/iot-hub-event-grid-routing-comparison
At the end of the day there is no good or bad way of consuming data coming from devices through IoT Hub.
Note that the Service SDKs for IoT Hub are designed to manage the instance of IoT Hub and manage the attached devices (provisioning, Twins, Direct Methods), but do not support telemetry (D2C) consumption because of exactly this (there is not a single way to consume messages/events from devices).- saramonteiroCopper ContributorThanks Olivier!