Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Mosquitto » Nodejs Cluster with MQTT client(Nodejs Cluster with MQTT client)
Nodejs Cluster with MQTT client [message #1843925] Tue, 24 August 2021 15:19 Go to next message
Ambar Adhikari is currently offline Ambar AdhikariFriend
Messages: 1
Registered: August 2021
Junior Member
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 08:31 Go to previous message
Roger Light is currently offline Roger LightFriend
Messages: 90
Registered: September 2013
Member
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
Previous Topic:Connection problem with Mosquitto
Next Topic:Can't publish to mqtt broker hosted in different subnet
Goto Forum:
  


Current Time: Thu May 02 15:43:54 GMT 2024

Powered by FUDForum. Page generated in 0.03648 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top