c# - 抛出 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException' 类型的异常

标签 c# mqtt

我正在连接到 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 });

异常消息

Exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException' was thrown

异常的堆栈跟踪

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()

我创立了一个 bug on the github , 但无解

异常消息根本没有帮助,里面没有内部异常。

最佳答案

我能够通过更改以下语句来解决此有线异常

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出现bug。

关于c# - 抛出 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException' 类型的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39917469/

相关文章:

c# - for循环超出范围

c# - 从一组 n 中找出 K 个元素的所有变体

flutter - 无法将类型 'MqttMessage' 的值分配给类型 'MqttPublishMessage' 的变量

python - paho-mqtt 订阅一次性消息

c# - 验证 ResetPassword 的 PasswordResetToken

c# - ImageButton 中的回发或回调参数无效

python - Google IoT 端到端示例中的连接错误

Azure IoT 中心 MQTT 用户名和密码字符长度限制

c# - 外壳文件错误 : missing assembly reference?

java - MQTT 代理在应用中?