Nodejs Cluster with MQTT client [message #1843925] |
Tue, 24 August 2021 11:19  |
Eclipse User |
|
|
|
I have a nodejs engine that uses MQTT to subscribe to messages from many IoT devices. As the number of IoT devices has increased, I want to run the nodejs engine in a cluster mode. This results in every cluster receiving all the MQTT messages. Is there a way to avoid this? A way in which one MQTT message will be received only once and the load of servicing the messages can be equally distributed.
Setup:
Nodejs Engine with MQTT client running via pm2 in an EC2 instance.
MQTT broker running in another EC2 instance.
|
|
|
Re: Nodejs Cluster with MQTT client [message #1843941 is a reply to message #1843925] |
Wed, 25 August 2021 04:31  |
Eclipse User |
|
|
|
Yes, you can use MQTT v5 shared subscriptions. The client doesn't even need to support MQTT v5.
If you want to subscribe to my/topic, then instead subscribe to $share/<sharename>/my/topic
The <sharename> effectively defines a group. Within that group, only a single client will receive a given publish message.
So for example, if you had the following subscriptions:
Client A: $share/group1/my/topic
Client B: $share/group1/my/topic
Client C: $share/group1/my/topic
Client D: $share/group2/my/topic
Client E: $share/group2/my/topic
And then published four messages to my/topic, then the clients would receive the following messages:
Client A: message1, message4
Client B: message2
Client C: message3
Client D: message1, message3
Client E: message2, message4
I hope that helps.
Regards,
Roger
|
|
|
Powered by
FUDForum. Page generated in 0.04591 seconds