gpt4 book ai didi

c# - 当 MQTTnet 服务器未运行时,PublishAsync 不会失败

转载 作者:行者123 更新时间:2023-12-02 20:22:03 24 4
gpt4 key购买 nike

我正在使用 MQTTNet,这是一个 .NET 库,用于来自以下链接的基于 MQTT 的通信

https://github.com/chkr1011/MQTTnet

我正在使用下面链接中的托管 MQTT 客户端

https://github.com/chkr1011/MQTTnet/wiki/ManagedClient

我有以下代码来发布消息到MQTT服务器

 var messagePayload = new MqttApplicationMessageBuilder()
.WithTopic("Topic1")
.WithPayload(message)
.WithExactlyOnceQoS()
.WithRetainFlag()
.Build();

try
{
await mqttClient.PublishAsync(messagePayload);
}
catch (Exception ex)
{
//Why I am not getting exception?
}

最佳答案

此行为是 MQTT 托管客户端的设计所致。它使用内部队列。所有发布的消息都会添加到此队列中,然后在服务器可用时发送到服务器。它还确保消息不会丢失,并且即使应用程序重新启动也可以重新发送。引用自项目 wiki。

All MQTT application messages are added to an internal queue and processed once the server is available. All MQTT application messages can be stored to support sending them after a restart of the application

关于c# - 当 MQTTnet 服务器未运行时,PublishAsync 不会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51133412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com