如何与设备客户端一起使用最后的意志和遗嘱?

发布于 2025-02-03 17:40:05 字数 168 浏览 3 评论 0原文

我正在使用官方Azure IoT SDK的DeviceClient来连接客户的IoT Hub。配置的原始纸是MQTT。现在,我有一个新的要求,以实施最后的意志和证明(LWT)消息。我知道此MQTT功能以及它如何与本机MQTT客户端一起使用。但是如何将其与偏差式使用?还是我需要切换到本机MQTT客户端(这会导致很多返工)?

I'm using the DeviceClient from the official Azure IoT SDK to connect to an IoT Hub from a customer. The configured protocoll is MQTT. Now I got a new requirement to implement a last will and testamant (LWT) message. I know this MQTT feature and how it would work with a native MQTT client. But how can I use this with the DeviceClient? Or do I need to switch to a native MQTT client (which would cause a lot of rework)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝色星空 2025-02-10 17:40:05

我终于找到了如何做到这一点:

MqttTransportSettings mqttSettings = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);
mqttSettings.KeepAliveInSeconds = 60; // Or whatever you like
mqttSettings.WillMessage = new WillMessage(QualityOfService.AtLeastOnce, will); // will is a normal Message instance
mqttSettings.HasWill = true;

this.client = DeviceClient.Create(this.eiotHost, authentication, new ITransportSettings[] { mqttSettings });

重要的是要设置Haswill属性,而不仅仅是Willmessage!

I finally found out how to do this:

MqttTransportSettings mqttSettings = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);
mqttSettings.KeepAliveInSeconds = 60; // Or whatever you like
mqttSettings.WillMessage = new WillMessage(QualityOfService.AtLeastOnce, will); // will is a normal Message instance
mqttSettings.HasWill = true;

this.client = DeviceClient.Create(this.eiotHost, authentication, new ITransportSettings[] { mqttSettings });

It is important to set also the HasWill property and not only the WillMessage!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文