Node Red: More efficient to use a "link out" node, or read MQTT In multiple times?

I am using the data from a single MQTT In source in multiple different flows. Which is less memory and CPU intensive:

A) To read the MQTT In channel three or four times in different flows, and use the values in each flow? (Sub question for extra credit - does NR treat this as a sort FIFO, where the first MQTT In to read the data removes it from the stack, and the others don't see it?)

  • or -

B) To read the MQTT In channel once, and then forward it to the other flows with a "Link Out" node?

Usually languages have a best practice for this sort of thing, yet NR seems unclear to me on this detail. Apologies in advance if I missed this in the documentation!

Thanks!

Scott

No. If you have mqqt-in nodes subscribing to the same topic[s] on multiple flows, they will all receive published messages.

I put mqqt-in nodes on each editor tab that uses the data.
If you find it a tidier approach, you could collect mqtt-in nodes on a single flow and link to the flows that need the data.
I'm pretty sure this would not offer any performance benefit.
You probably still need multiple mqtt-in nodes to handle different topics.

The way it works is the mqtt config node make the connection to the broker then the in and out nodes are "links" to that that then receive or send the specific topics you want. So if you have one in node then a bunch of links, or multiple in nodes, makes no significant difference. In general it's down to your preference and understanding of your flow. The main reason for having the one mqtt-in node would be if you need to change the topic it subscribes to - as you then only have to change it in one place, but then again you may want (or be able) to have different topics on each.

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