2016-10-07 623 views
1

我正在連接到mqtt,我收到了一個無用的異常。類型'uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException'的異常被拋出

代碼

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 }); 

異常消息

類型 'uPLibrary.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() 

我成立了一個bug on the github,但沒有解決

異常消息是無益可言,而且,裏面有沒有內在的異常。

回答

0

我能夠通過改變以下語句

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有錯誤時,同時指定多個主題。

2

好多了:

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 
    } 
); 
+0

這也爲我工作。 –

相關問題