Open codeasone opened 7 years ago
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: https://github.com/emqtt/emqttd/issues/921
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.
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
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.
Hello, Is there an "official" solution for this?
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.
Is this issue still present with the MQTT 5 client? It seems I'm facing the exact same issue.
After looking at the code, I'd say the following few lines should use the topic with the $share/{id}
prefix stripped:
Is there any news about when it will be released?
Submitted this fix awhile ago, but would love to see some feedback on it - https://github.com/eclipse/paho.mqtt.java/pull/911
Callbacks don't get called when subscribing to shared subscriptions, e.g.
$share/group/topic
, using thesubscribe(String topicFilter, int qos, IMqttMessageListener messageListener)
API.However, shared subscriptions work as expected when using the
setCallback(...)
API before invokingsubscribe(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...
HEAD
ofdevelop
branch throws exceptions with my test program suggesting a regression wrt.1.1.x
API, which may or may not be related.