SOLVED

What's the best way for an external application to read data from IoT Hub?

Occasional Contributor

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 Event Hub compatible built-in endpoint. Besides that, the example I found use it. Like this one: Real-time data visualization of your IoT hub data in a web app | Microsoft Docs

But, for this purpose, one would use the Event Hub SDK. See EventHubConsumerClient class | Microsoft Docs.

I was wondering if we couldn't do the same using the Azure IoT Hub SDKs | Microsoft Docs.

From the Git Hub repository, I can only see C2D messaging support, but taking a deeper look at ServiceReceiver class | Microsoft Docs I thought that maybe this is an alternative.

 

Does anyone has some info to share about this?

Pros, cons? If my understanding is right?

2 Replies
best response confirmed by saramonteiro (Occasional Contributor)
Solution
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).