0
votes

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.

  1. 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.
  2. 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.

1
Is this the MQTT.js client or the Paho Webclient JavaScript client?hardillb
Actually it doesn't matter the feature I was thinking of is only in the Paho Java client (per subscription callbacks)hardillb

1 Answers

0
votes

Option 1 is REALLY not a good idea, it just makes so much extra work, maintaining the connection for all the separate clients and adds extra overhead to the broker.