Azure IOT 服务客户端/RegistryClient : What is the recommended frequency of CloseAsync?

标签 azure azure-iot-hub azure-iot-sdk

Microsoft.Azure.Devices.ServiceClientMicrosoft.Azure.Devices.RegistryManager 都具有 ConnectFromConnectionStringCloseAsync > 方法。

我们是否应该像使用其他 .NET connection-close 模式(例如 ADO.NET 连接、Redis 连接、套接字等)一样使用它们?当我使用类似的对象时,我会尝试尽快CloseDisposable.Dispose()它们。

访问同一个 IOT 中心时,对 Microsoft.Azure.Devices 对象执行相同的操作有什么好处和坏处?我运行的代码将各个 RegistryManagerServiceClient 实例视为单例,它们在应用程序的整个生命周期(可能是几周或几个月)中使用。我们是否通过在这段时间内保持这些对象“打开”而使自己短路?

最佳答案

正如 @David R. Williamson 所指出的,以及 this discussion on GitHub ,一般建议将 RegistryManagerServiceClient 注册为单例。

对于 ASP NET Core 或 Azure Functions,可以在启动时按如下方式完成:

ConfigureServices(services)
{
  services.AddSingleton<RegistryManager>(RegistryManager.CreateFromConnectionString("connectionstring"));
}

关于Azure IOT 服务客户端/RegistryClient : What is the recommended frequency of CloseAsync?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45598284/

相关文章:

Azure 认知服务 - TTS

c# - VSTS - 在部署之前使应用程序离线

php - 如何使用 PHP 的共享访问签名在 azure 中上传 blob?

java - Azure Android Blob 上传 IOException

python - Azure IoT 中心设备 x509 自签名证书 (Python MQTT)

sql - 通过流分析将带有数组的流传递到 SQL 中的多行

c# - 在同一进程中处理消息并将其发送到云端而不丢失数据的良好设计是什么?

java - 使用 x509 正确配置 Azure IoT 中心 DPS 组注册

azure - 是否可以依次启动各个iot-edge模块?如果可以的话,该怎么办呢?

azure - Azure IoT 上的软件更新