upllibrary . networking . m2mqtt . exceptions . mqttclientex

本文关键字:mqttclientex exceptions m2mqtt networking upllibrary | 更新日期: 2023-09-27 18:12:06

我正在连接到mqtt,我正在接收一个无用的异常。

string smsTopic = ConfigurationManager.AppSettings["MQTT_SMS_Topic"];
string emailTopic = ConfigurationManager.AppSettings["MQTT_Email_Topic"];
string pushTopic = ConfigurationManager.AppSettings["MQTT_PUSH_Topic"];
string socialTopic = ConfigurationManager.AppSettings["MQTT_SOCIAL_Topic"];
client = new MqttClient("somehostname");
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
client.Subscribe(new string[] { smsTopic, emailTopic, pushTopic, socialTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
<<p> 异常消息/strong>

ulibrary . networking . m2mqtt . exceptions类型异常。MqttClientException'被抛出

异常的堆栈跟踪

at uPLibrary.Networking.M2Mqtt.Messages.MqttMsgSubscribe.GetBytes(Byte protocolVersion) in c:'Users'ppatierno'Source'Repos'm2mqtt'M2Mqtt'Messages'MqttMsgSubscribe.cs:line 187
at uPLibrary.Networking.M2Mqtt.MqttClient.Send(MqttMsgBase msg) in c:'Users'ppatierno'Source'Repos'm2mqtt'M2Mqtt'MqttClient.cs:line 1028
at uPLibrary.Networking.M2Mqtt.MqttClient.ProcessInflightThread() in c:'Users'ppatierno'Source'Repos'm2mqtt'M2Mqtt'MqttClient.cs:line 1954
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

我在github上发现了一个bug,但是没有解决方案

异常消息是没有帮助的,它里面没有内部异常。

upllibrary . networking . m2mqtt . exceptions . mqttclientex

我可以通过修改下面的语句

来解决这个连线异常
client.Subscribe(new string[] { smsTopic, emailTopic, pushTopic, socialTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });

client.Subscribe(new string[] { smsTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
client.Subscribe(new string[] { emailTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
client.Subscribe(new string[] { pushTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
client.Subscribe(new string[] { socialTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });

似乎mqtt在同时指定多个主题时存在错误。

好多了:

client.Subscribe(new string[] 
    { smsTopic, emailTopic, pushTopic, socialTopic }, 
    new byte[] { 
         MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, 
         MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE,
         MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE,
         MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE 
    }
);