Reputation: 5368
Is it possible to get notified that a device has connected to IoT hub without polling?
The only option I've found is to poll RegisteryManager.GetDevicesAsync()
and loop through the registered devices to see if they are connected or not. I could poll, however I have no idea what sort of throttling limits exist.
That code looks like:
var devices = await registryManager.GetDevicesAsync(maxCountOfDevices);
if (devices != null)
{
foreach (var device in devices)
{
// do something with the connection state like
// notify services
device.ConnectionState
}
}
What I'd like is to be able to get all registered devices, keep them in memory, and just listen for connection events.
Upvotes: 1
Views: 2360
Reputation: 2416
Microsoft Azure IoT team suggests implementing the heartbeat pattern because connectionState is not accurate: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-identity-registry#device-heartbeat
Upvotes: 1
Reputation: 2276
I Tried it with operation monitoring in Azure IOT Hub. It provide an event hub endpoint to read the verbose operation. So here i find the event of connection and disconnection of IOT device to IOT hub. But now the issue is device messages and connection/disconnection events are async.
Upvotes: 0