0
votes

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

1

1 Answers

0
votes

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.