Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbacks not invoked for shared-subscriptions #367

Open
codeasone opened this issue May 4, 2017 · 10 comments
Open

Callbacks not invoked for shared-subscriptions #367

codeasone opened this issue May 4, 2017 · 10 comments

Comments

@codeasone
Copy link

codeasone commented May 4, 2017

Callbacks don't get called when subscribing to shared subscriptions, e.g. $share/group/topic, using the subscribe(String topicFilter, int qos, IMqttMessageListener messageListener)API.

However, shared subscriptions work as expected when using the setCallback(...) API before invoking subscribe(String topicFilter, int qos).

I have written a simple Java application which reproduces the issue.

https://github.com/codeasone/shared-subscriptions-issue

This issue impacts wrappers such as the Clojure library machine-head, which is what led me here...

  • [ ✓] Bug exists Release Version 1.1.1 ( Master Branch)
  • [ ?] Bug exists in Snapshot Version 1.1.2-SNAPSHOT (Develop Branch)

HEAD of develop branch throws exceptions with my test program suggesting a regression wrt. 1.1.x API, which may or may not be related.

@yogin16
Copy link

yogin16 commented May 8, 2017

Great explanation in the issue. We are also facing similar issue.

Upon checking further I found out that in CommsCallback's deliverMessage it does exact topicName matching with filter as per the standard. And as $share or $queue is not defined in MQTT standard - it is not matching. If the message hasn't been delivered to a per subscription handler, it would give it to the default handler - as it is working using setCallback(...)

Should I go ahead and add support for external topic matcher in CommsCallback? If no external topic matcher registered then default to MqttTopic.isMatched(topicFilter, topicName)

The issue was notified in emqttd broker as well: emqx/emqx#921

@jpwsutton
Copy link
Member

As @yogin16 says, Shared Subscriptions aren't in the MQTT 3.1.1 specification, there are some guidelines on topics starting with $ though (http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718108). I'm hesitant about adding things that would take us off specification as it feels like a bit of a slippery slope. MQTTv5 will include shared subscriptions and we will definitely be implementing them in the Paho Java v5 client. Whether we add it to the 3.1.1 client though is something that I think should be discussed with the wider Paho community.

@yogin16
Copy link

yogin16 commented Jul 9, 2017

I was able to solve this by adding a MqttCallback implementation for custom routing of unmatched topic filter.

Here is the example: https://github.com/yogin16/paho-shared-sub-example/blob/master/example/src/src/SharedSubCallbackRouter.java

@icraggs icraggs added this to the 1.2.1 milestone Nov 16, 2018
@icraggs icraggs reopened this Nov 16, 2018
@icraggs icraggs modified the milestones: 1.2.1, 1.3.0 Nov 21, 2018
@icraggs
Copy link
Collaborator

icraggs commented Nov 22, 2018

We could have a method on the client (for MQTT V3 - MQTT V5 has it in the spec), which gives a list of prefixes (in regex format?), which are ignored in topic matching. This would cater for multiple different implementations.

@vborcea
Copy link

vborcea commented Jan 28, 2019

Hello,
Is there an "official" solution for this?

@icraggs
Copy link
Collaborator

icraggs commented Jan 28, 2019

I like my idea above of specifying the prefixes to ignore in a method. Should be pretty easy to implement. I'll do that soon if no-one else does.

@icraggs icraggs modified the milestones: 1.2.1, 1.2.2 Feb 18, 2019
@icraggs icraggs modified the milestones: 1.2.2, 1.2.3 Sep 23, 2019
@rdasgupt rdasgupt modified the milestones: 1.2.3, 1.2.4 Apr 2, 2020
@pschichtel
Copy link

Is this issue still present with the MQTT 5 client? It seems I'm facing the exact same issue.

@pschichtel
Copy link

After looking at the code, I'd say the following few lines should use the topic with the $share/{id} prefix stripped:

https://github.com/eclipse/paho.mqtt.java/blob/master/org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/MqttAsyncClient.java#L1301-L1305

@yuremboo
Copy link

Is there any news about when it will be released?

@nwest1
Copy link

nwest1 commented Feb 14, 2024

Submitted this fix awhile ago, but would love to see some feedback on it - #911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants