Search code examples
c#azureazure-iot-sdkazure-iot-hub-device-management

How to get Cloud to Device Pending Messages Count


I am using Azure IoT Hub. In Azure portal, it is easy to see how many cloud to device messages are pending in the queue.

I want to read this value using C# SDK

enter image description here


Solution

  • I finally found the working answer as follows:

    using Microsoft.Azure.Devices;
    
    RegistryManager registryManager = RegistryManager.CreateFromConnectionString("registryreadconnectionstring");
    
    Device device = await registryManager.GetDeviceAsync("device-id");
    
    var count  = device.CloudToDeviceMessageCount;