I am building a javascript app which is going to be a mqtt client. It needs to subscribe to multiple topics. I can see that there are two ways to implement this.
- Make multiple client connections. On each client connection subscribe on a single topic. Then the onMessage handler will be fired on that client for that topic only. This means I will have multiple mqtt connections.
- Make a single client connection. Subscribe to multiple topics on that one client. Then when onMessage fires, I need to inspect the message.topic and route that message to the subscriber callback method which subscribed to that topic and I need to cater for the # and * wildcards.
Currently I am implementing method #2. But I would like to get your opinions on which is the best method and why.