0

Today I posted this topic MQTT know if a client is subscribed

I would like to try something, but I would like to know if is feasible, may be I'm complicating the things, so if you have another suggestion please feel free

let's suppose that we have the topic temperature/subscription

First

Client A subscribes to subscription (or in other words temperature/subscription) if he doesn't receive a payload (a retain message)

then

Client A publishes to subscription with a payload of 1 or "online" as a retain message

and subscribes to the temperature topic

Now, Client B

again, subscribes to subscription if he receives a payload = someone is already subscribed (Client A) So, he can't subscribe to temperature topic

I still need to add the LWT message, but first I want to start with something simple.

Is it feasible to do this? so I this way I can see if someone is subscribed or not to a topic

Community
  • 1
  • 1
marhg
  • 659
  • 1
  • 17
  • 30

1 Answers1

0

As we discussed last time, that will work, but it has a huge gaping timing window between checking for a message on temperature/subscription and publishing a message to it to claim the subscription.

Also you need to use the client id of as the marker because retained messages will survive a broker restart, which will disconnect all the client, so client A won't know it still holds the "lock" after a broker restart.

The LWT is only there for is client A crashes and then it will wait for the TTL for the connection to expire before sending the message, you need to explicitly clear that topic if client A disconnects cleanly.

In summary this is a really bad idea, trying to retro fit a concept that MQTT is not suited to.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • understood.. thank you again hardillb, the thing is that i need to find some way to do that, or at least limitate the subscriptions of a channel, that only one can be subscribed :/ – marhg Aug 12 '16 at 17:38
  • What about the plugin MQTT Message Log? – marhg Aug 12 '16 at 17:46