Reputation: 15
I'm using m2mqtt to get message ,but I can't individual subscribe two topic
I use client.Subscribe to Subscribe two topic,and use client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) to get message
But two topic's message is mixed together . Is there any meth to divide it?
Upvotes: 1
Views: 1287
Reputation: 59608
Just put an if statement into the message handler to branch based on the incoming messages topic e.Topic
.
You can always write functions to handle the different message types and just call these from the message handler and pass the MqttMsgPublishEventArgs
object to those functions.
Upvotes: 1
Reputation: 10065
the client provides just one handler for receiving messages. You can find information about the topic in the MqttMsgPublishEventArgs (there is the Topic property for that). It doesn't make sense for a client having different handlers one for each topic you have subscribed to (maybe something impossible because you don't know how many topics the user subscribes upfront).
Upvotes: 1