eclipse-paho / paho.mqtt.golang

Other
2.77k stars 534 forks source link

support of shared subscription in paho.mqtt.golang #647

Closed Abhijithm2447 closed 1 year ago

Abhijithm2447 commented 1 year ago

Hi,

I found one statement on documentation of paho.mqtt.golang that this library is not supporting MQTT-5. However, I am able to use shared subscription with use of this library and code inside attached file. As shared subscription is part of MQTT-5 then how this library is supporting shared subscription if MQTT-5 is not supported by this library?

code file: shared_subscription.go.txt output file: output

MattBrittan commented 1 year ago

Shared subscriptions are supported by a range of V3 brokers (not part of the v3 standard but there is nothing in the standard prevents the feature being implemented and some of these implementations are from before v5 was released)..

Note: Please see the readme for places to ask questions like this (this section is intended for issues with this specific library, not general questions - testing with something like mosquitto_sub would have quickly demonstrated that shared subscriptions work with other clients).

Abhijithm2447 commented 1 year ago

Is there any thorough testing happened for shared subscription using paho.mqtt.golang with either v3 or v5 broker? If Yes, can I get some references please.

MattBrittan commented 1 year ago

The feature is implemented in the broker; it has almost no impact on the client (the one possible impact is ignoring the $share/groupname in the router, which this library does).

Edit for clarity "paho.mqtt.golang with either v3 or v5 broker?" - paho.mqtt.golang does not support MQTT v5 (but most brokers support both versions).

Abhijithm2447 commented 1 year ago

Just for confirmation, what is the meaning of router in your comment? Is it topic name or broker or something else?

MattBrittan commented 1 year ago

what is the meaning of router in your comment?

The router is part of this library; it's what works out what user functions should be called when a PUBLISH is received. So when you call:

t := c.Subscribe(TOPIC, QOS, h.handle)

The client adds an entry in the router such that messages to TOPIC will result in h.handle being called. The reason that this needs to take shared subscriptions into account is that if you call:

t := c.Subscribe(`$share/group1/foo`, QOS, h.handle)

Then the broker will deliver messages with the topic foo (not $share/group1/foo). So we need to remove the $share/group1/ when adding the entry in the router.