Shared MQTT subscriptions

Hi all
I use emq as my mqtt server and it supports shared mqtt subscriptions. I want to use this functionality to have more than one flow have an mqtt in node that will subscribe to the same topic, as to offer round robin load sharing on mqtt.

I have tested this functionality by writing two clients that subscribe to $share/accQ/topic1 and one server that publishes to topic1. This works great, but when I create a mqtt out node that publishes to topic1 and two mqtt in nodes that subscribe to $share/accQ/topic1, connected to a debug node, both nodes processes the payload, instead of a round robin implementation.

Has anybody tried this approach before and got it to work?


Update: I tested with the two node-red mqqt in nodes plus the 2 nodejs clients all at the same time and found that there is definitely round robin processing happening, with either one of the nodejs client processing or both the node-red mqtt in nodes processing. So, it looks like node-red mqtt in node will always process the payload even in a shared subscription setup.

If both of your MQTT In nodes are using the same MQTT Broker configuration node then both nodes will get every message.

This is because there is only one connection between Node-RED and your broker. When a message arrives at the MQTT Broker configuration node, it has to match it against all of the MQTT In nodes to find which has a matching subscription and pass it to those nodes. You have two MQTT In nodes with matching subscriptions so they both get every message.

If you want to make use of the round-robin feature of emq, then you need to give each MQTT In node its own MQTT Broker configuration node. That means they each connect as a separate client and the broker can then to the round-robin between them.

Fantastic, thanks very much. It works like a charm.

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