Multiple subscriptions to same topic
- [x] Bug exists Release Version 1.1.1 (Master Branch)
- [ ] Bug exists in Snapshot Version 1.1.2-SNAPSHOT (Develop Branch)
I have two classes which should react to messages in the same topic. But I noticed I can't do that easily, because you store subscriptions as Map<topic, callback>, so when I subscribe to the same topic, the new callback overwrites the previous callback. I sugges using Map<topic, Set<callback> instead.
Subscribing to the same topic with MQTT results in only one subscription, which would be a problem for the subscribe call as it issues an MQTT subscribe as well.
To allow this to work, a different model will be needed, perhaps un/setTopicHandler calls. Perhaps more subscription tracking in un/subscribe.
Couldn't you just chesk if key for given topic exists in Map and if callbacks Set is empty and only do MQTT (un)subscripbe according to that?
Bump. I was hit by this again, when trying to use Coroutines Flow. My SO question.
Any news on this?
Now that we have SharedFlow in Kotlin, it's easy to work around this limitation. :+1:
My view is that this is something to be solved in the application, rather than the MQTT library. The MQTT library is reflecting the behaviour of MQTT - the more that behaviour is hidden the more scope there is for misunderstandings and a higher maintenance cost.