Arbitrary amount of simultaneous mqtt connections

Let's say there is an array of mqtt connections to be made. How can node red create X amount of such connections?

Perhaps it would be better to have just 1 connection and differentiate on request data, but then there is an issue on security. With 1 connection per device, we can ensure this security. But without, one could debug the request, modify it and access other device data.

What do you mean by 'connections'. Do you mean that you have multiple mqtt brokers that you need to connect to, or multiple topics that you need to subscribe/publish?

1 Like

At a guess, you are referring to the fact ThingsBoard offers MQTT connectivity to its "devices" (the ones you setup in its system) & you are asking how to make multiple connection.

The answer is to create 1 broker config per device (and enter the unique security details and client ID per broker config)

I was helping another user in a similar situation - they were seeing random timeouts with 60 broker configs and was asking what the limit was. There is no set limit. In fact, I did a demo connecting to 80 brokers and it was rock solid. So it depends on your env.

Personally, I think it is super wasteful and an arduous task with little real benefit. Managing that many broker connection setup would be a nightmare.


As for setup dynamically via an array - it is possible so long as you have pre-created the requisite number of broker configs. I wont go into further detail at this point tho.

1 Like

Thanks all. Agree with all your points and now need to rethink this one. For little more background, I want to make a custom widget in Thingsboard to communicate with Teltonika to create connections to devices and return url. This isn't possible directly due to CORS on some of the Teltonika API endpoints. But it is possible through node red. Plan was to have some sort of shared or easy way of managing it. You could potentially connect to Thingsboard with just the TB device id and token, this could be stored in meta-data of Teltonika device. So all node red would have to do is to fetch devices from Teltonika, get all IDs and tokens and connect to each TB device using that info.

That would solve the security risk of picking up the request in browser debug, change device id and get connection url to another device. However agree it sounds very wasteful as these will only send traffic very rarely.

So instead, I'm thinking about sending a request from thingsboard with the device id and the user's session token. Then try and access the thingsboard device in node red with the session token to validate access rights for the user to that device. And only then go on to teltonika. This would only require one mqtt connection.

Onto experimenting :smiley: