paho.mqtt.java icon indicating copy to clipboard operation
paho.mqtt.java copied to clipboard

Multiple subscriptions to same topic

Open Pitel opened this issue 8 years ago • 6 comments

  • [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.

Pitel avatar Jun 28 '17 07:06 Pitel

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.

icraggs avatar Jul 19 '17 20:07 icraggs

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?

Pitel avatar Jul 20 '17 06:07 Pitel

Bump. I was hit by this again, when trying to use Coroutines Flow. My SO question.

Pitel avatar Oct 29 '19 08:10 Pitel

Any news on this?

EP-u-NW avatar May 30 '20 17:05 EP-u-NW

Now that we have SharedFlow in Kotlin, it's easy to work around this limitation. :+1:

Pitel avatar May 14 '21 07:05 Pitel

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.

icraggs avatar May 14 '21 11:05 icraggs