Search code examples
mqttmqttnet

MQTTnet getting Topic names of Topics you are subscribed to


Is there an option for getting Topics that the client is currently subscribed to? I'm currently saving all this data locally in client app DB, but I think that just add the unnecessary difficulty to my application and introduces some bugs (if the application DB is cleared on application reinstalled) and I rly want to remove all of that. I looked at documentation but seemed to be unable to find anything related to that.

So my question would be: Is getting names of the topic I have subscribed to even possible? If so - how?

Or should I stick with my save in local DB approach?


Solution

  • No, the MQTT client has no need to keep a list of subscribed topics as all the matching is done in the broker, which maintains the list associated with the client session.

    This also means it's possible for a client to crash, reconnect (with the same clientId and cleanSession false) and the broker will continue to send all matching messages as the subscriptions will be maintained with the session.

    If you need to remember what topics the app has subscribed to then you have to keep your own list.