MQTT V5 performance: dynamic subscription VS single topic

Hi, is there someone that can explain how connections works?
I mean, in terms of broker's load (but even regarding node-red ), is there a difference if I subscribe via two MQTT-in node ore just via a dynamic one?
This because with the single topic I can check to not receive messages published by the same client, while I cannot do it with the dynamic one. So, in this last case, I have to add a topic level in order to differentiate the messages sent by the same client.
Since I have lots of messages each second, I wanted to understand which is the best solution.

You can.

When you subscribe dynamically, the topic can be a string, object, or an array:

Subscribe 1 (single string)

msg.action = "subscribe"
msg.topic = "testing_dyn_con/test1"

Subscribe 2 (strings)

msg.action = "subscribe"
msg.topic = ["testing_dyn_con/test1", "testing_dyn_con/test2"]

Subscribe 3 (using strings and options)

msg.action = "subscribe"
msg.topic = [
  {
    "topic": "testing_dyn_con/test1",
    "nl": true, //no local - Do Not Receive Messages Published By This Client 
    "ral": true, //Keep retain flag of original publish (same as 'mqtt in' default)
    "rh": 0, //Retained Message Handling: 0 = Send retained messages, 1= Only send for new subscriptions, 2= Do not send
  },
  {
    "topic": "testing_dyn_con/test2",
    "qos": 2,
    "nl": false,
  },
  "testing_dyn_con/test3"
]

Thanks so much @Steve-Mcl. I didn't know this way of setting options with dynamic subscription. I thought I could set just Topic and QoS. Exactly what I was looking for.
Ok, now in order to avoid bottlenecks and better understand how MQTT / node-red connections works, it is correct to say that:

  • any connection channel is creates when I set the server tab (username, password and ID client)
  • so, all messages with the subscribed topics are delivered by this channel.
  • even if I use more mqtt-in node, all set with the same server parameter (selecting it by the menĂą and no creating a new one each time), the connection channel is always the same. So, just one.
  • in this case there is no difference as workload in use more single MQTT-in or just one as a dynamic subscription

Is that correct?

1 Like

Not certain that translates well (sorry).

I will answer what I think you are asking (hopefully you can pick out an answer)...

Not sure I understand this statement/question?
When you create a broker connection (MQTT config) it is one single connection. You can (should) set it to NOT AUTO CONNECT - then at a later time, send an action to connect

If I understand, you are asking "All topics subscribed via 1 MQTT-IN node are emitted by the same MQTT-IN node only?" - that is correct :white_check_mark:
(See ramblings below for more)

Yes, just one connection to the broker :white_check_mark:

No measurable difference.


Some ramblings that might help...

  • If you create 1 MQTT-Broker config & have 1, 2, 5, 100 additional MQTT-IN nodes, they will ALL use the same SINGLE connection.
  • If you disconnect this single MQTT-Broker (msg.action="disconnect") ALL nodes that use this connection will become disconnected.
  • Any topic you dynamically subscribe to will only emit events from THAT node

Thanks @Steve-Mcl, I think I got the answers.
Pratically I wanted to understand if once I set the server (broker) parameters within the dedicated tab, selecting always this configuration at the end the broker connection will be just one, no matter how many mqtt-in node I use.
So even if I use 10 mqtt-in node, all with the same broker configuration, the broker connection will be just one and all the messages will be delivered trough this one single connection.
From your reply I understand that yes, it works like this
Thanks

1 Like

something elsse to think about. @Lupin_III, if you want a single topic displayed in 2 locations, you dont need to set up another mqtt node. you can simply use a link node out from your Mqtt node. and then on what ever flow tab you are trying to send that info to you use a link in.
here is a silly example but effective

[{"id":"9f0e6c0aabf5d34f","type":"inject","z":"ef1fc105685aed46","name":"FakeMqtt","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"just a test","payload":"","payloadType":"date","x":615.6666870117188,"y":609,"wires":[["3c04179f41b36ca6"]]},{"id":"3c04179f41b36ca6","type":"link out","z":"ef1fc105685aed46","name":"","mode":"link","links":["8708e448cf096cae"],"x":812.6666870117188,"y":608,"wires":[]},{"id":"8708e448cf096cae","type":"link in","z":"ef1fc105685aed46","name":"","links":["3c04179f41b36ca6"],"x":675.6666870117188,"y":678,"wires":[["ede0226fddbda16b"]]},{"id":"ede0226fddbda16b","type":"debug","z":"ef1fc105685aed46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":789.6666870117188,"y":677,"wires":[]}]

cheers!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.