mqttjs / MQTT.js

The MQTT client for Node.js and the browser
Other
8.53k stars 1.41k forks source link

MQTT.js and shared subscriptions #789

Open jkinghed opened 6 years ago

jkinghed commented 6 years ago

Several MQTT brokers are now supporting shared subscriptions (HiveMQ, VerneMQ, EMQ) from the v5 MQTT standard.

The syntax of subscribing to a shared topic seem currently differs based on broker:

HiveMQ $share:sharename:topic/subtopic/etc (details)

VerneMQ $share/sharename/topic/subtopic/etc (details)

EMQ $queue/topic/subtopic/etc or $share/sharename/topic/subtopic/etc (details)

The MQTT v5 standard specifies $share/sharename/topic/subtopic/etc (details)

So, at least VerneMQ and EMQ both works with the standard.

Any messages published to topic topic/subtopic/etc should then be distributed by the broker to the different subscribers using the $share/sharename/topic/subtopic/etc subscription, but only 1 of the subscribers will get the message. (Which subscriber depends on broker and settings.)

Using this feature makes load balancing very easy.

However, it seems MQTT.js does not yet support this as messages published to a topic with shared subscriptions from MQTT.js are ignored.

Are there any plans to implement this?

mcollina commented 6 years ago

Are there any plans to implement this?

Would you like to contribute? See #651 .

jkinghed commented 6 years ago

Not sure I have the required skills, but I'll try to find time to look into it. Thanks.

markusapfler commented 5 years ago

Is there any progress on the implementation of this feature?

jkinghed commented 5 years ago

Is there any progress on the implementation of this feature?

It has been implemented in Node-Red - source - which uses MQTT.js.

The issue is that MQTT.js default client treats $share/sharename/topic/subtopic/etc as a literal topic, so when something is published on topic/subtopic/etc it is ignored, as the subscription is for $share/sharename/topic/subtopic/etc

However, in Node-Red - and I'm not sure I'm correct on the sequence of things here - it seems that the handler for the subscription overrides the default and validates each message against the actual topic without $share/sharename/ prefix. code

So if you were to do something similar in your client, you might get it to work...

Paic commented 4 years ago

Hey 👋 We had this problem today (can't remember the version, I'll update my post later) and I just tested right now with package version 3.0.0 and it looks like everything is fine (using VerneMQ, even though it doesn't really matter).

Can someone confirm this is fixed ?

github-actions[bot] commented 1 year ago

This is an automated message to let you know that this issue has gone 365 days without any activity. In order to ensure that we work on issues that still matter, this issue will be closed in 14 days.

If this issue is still important, you can simply comment with a "bump" to keep it open.

Thank you for your contribution.

github-actions[bot] commented 1 year ago

This issue was automatically closed due to inactivity.

SaumilShah-7 commented 1 year ago

Unable to use shared subscription in the latest version of MQTT.js. Client keeps subscribing in loop and doesn't consume any message. Will this be supported or is there a work-around ?

fp-caregility commented 7 months ago

Unable to use shared subscription in the latest version of MQTT.js. Client keeps subscribing in loop and doesn't consume any message. Will this be supported or is there a work-around ?

I am also seeing this behavior. Did you find a solution?

robertsLando commented 7 months ago

Could someone share a minumum reproduction script?