【问题标题】:Azure Cloud to Device direct message using Cloud Service-Worker Role使用云服务工作者角色的 Azure 云到设备直接消息
【发布时间】:2018-08-17 03:51:51
【问题描述】:

我们正在开展一个项目,该项目需要在设备之间交换大量消息/命令。

我们正在使用 Cloud Service Worker 角色来处理命令并使用 Cloud to Device Direct 方法发送到相关设备。

worker 角色配置为 A2V2-2 Core,4 GB RAM。worker 角色容量没有问题。CPU 和内存尽在掌控。

对于较少的消息/命令处理其工作正常(例如 500 条消息)。但是当没有消息增加时,我们将面临性能问题(例如 1000 条消息)。我们的目标是

我们使用以下代码行使用直接方法发送消息。寻找更好的方法来在每次直接方法调用后处理服务客户端对象。

 var methodInvocation = new CloudToDeviceMethod(methodInfo.MethodName) { ResponseTimeout = TimeSpan.FromSeconds(methodInfo.ResponseTimeout) };
            //set the payload
            methodInvocation.SetPayloadJson(methodInfo.Payload);

            //invokes direct method
             var response = _serviceClient.InvokeDeviceMethodAsync(methodInfo.DeviceId, methodInvocation);

            if (_serviceClient != null)
            {
                //closes the service client connection
                _serviceClient.CloseAsync();
                _serviceClient.Dispose();
            }

【问题讨论】:

  • 1.您能否查看“Cloud-to-device communications guidance”,因此请确保您的案例必须使用直接方法,以便需要立即确认结果的通信。直接方法通常用于设备的交互控制,例如打开风扇。 2. 1000条消息,一秒钟发生多少时间?
  • 谢谢丽塔韩。
  • 由于阈值限制,我们不能使用云到设备消息方法。所以我们只能选择直接方法。我们正在做 100 到 150 条消息/秒

标签: c# azure azure-iot-sdk


【解决方案1】:

终于找到了解决办法。Azure服务客户端对象没有正确关闭和释放。我们在直接方法调用成功后显式关闭和释放服务客户端对象。

  //closes the service client connection
  await _serviceClient.InvokeDeviceMethodAsync(methodInfo.DeviceId, methodInvocation);
 _serviceClient.CloseAsync().Wait();
 _serviceClient.Dispose();

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-07
  • 1970-01-01
  • 2019-01-13
相关资源
最近更新 更多