如何获取云到设备的待处理消息计数

时间:2019-07-04 13:45:38

标签: c# azure azure-iot-sdk azure-iot-hub-device-management

我正在使用Azure IoT中心。在Azure门户中,很容易看到队列中有多少云到设备消息挂起。

我想使用C#SDK读取此值

enter image description here

2 个答案:

答案 0 :(得分:0)

我终于找到了可行的答案,如下所示:

using Microsoft.Azure.Devices;

RegistryManager registryManager = RegistryManager.CreateFromConnectionString("registryreadconnectionstring");

Device device = await registryManager.GetDeviceAsync("device-id");

var count  = device.CloudToDeviceMessageCount;

答案 1 :(得分:-1)

var device = new Microsoft.Azure.Devices.Device("device-id");
var cloudToDeviceMessageCount = device.CloudToDeviceMessageCount;