It is possible to get all possible topics in mqtt broker

Viewed 98

I want a way to get list of all possible topics in mqtt broker, but I don't want to subscribe to all possible topics using wildcards with # or +. I just want all possible topics.

If it is possible and anyone has any idea about it, please let me know.

1 Answers

It depends on the broker. The MQTT specification says nothing about enumerating topics, so there is no standard mechanism for doing this. It's possible that certain brokers may provide a way.

This is less meaningful than you might think. "All available topics" would really mean "all possible topics". Topics are not "available" or "unavailable". Publishers do not register topics that they publish to. A publisher might publish to a topic a single time and never again. A publisher might publish to a topic in the future; at the present the broker would have no way to know that this topic might be used.

There are only three meaningful ways that topics have any kind of persistence:

a client may subscribe to a topic - the broker has to track subscriptions, so that it may transmit messages to the correct clients. Unless the client is using a session or QoS 1 or 2, the broker may forget about this subscription, and therefore topic, when the client disconnects.

a client might have published a message with QoS 1 or 2 or with the retain flag. In that case the broker will persist the message for some time and will need to remember that topic it was sent to.

a broker may support access control lists (Mosquitto does) - such a broker might make it possible to query which topics have access control.

Otherwise, topics are best thought of as transient. The broker really knows very little about them. The broker cannot predict the future and it is impractical for the broker to remember any more of the past than is absolutely necessary.

If your design requires knowledge of "all topics", you should rethink it.

Related