Request all published topics

2019-06-24 06:52发布

问题:

I'm using mosquitto for my MQTT Broker. I was wondering if it would be possible to request all published topics?

Thus NOT by subscribing to everything, i.e. '#'.

EDIT: I don't want to subscribe to every available topic. I'm just looking for a way to retrieve all published topics. The broker could for instance response with a string array containing all the published topics.

回答1:

Manageability of MQTT brokers is very immature at this point. I also don't know of a way to retrieve the list of published topics from any broker. But, there are standardization efforts, eg. with the $SYS topic tree https://github.com/mqtt/mqtt.github.io/wiki/SYS-Topics.

Other brokers are manageable via SNMP, eg. MessageSight https://www.ibm.com/support/knowledgecenter/en/SSCGGQ_1.2.0/com.ibm.ism.doc/Monitoring/admin00008_.html . It can list the topics in its WEB interface, but I don't know of a programmatic way to retrieve them.



回答2:

If you send "EVERY" message to broker with retain message = True, then you can:

  1. Connects to server with subscribe '#'
  2. Check all the retain message and their topic (save these published topics)
  3. Unsubscribe '#'
  4. Subscribe every topics you got


回答3:

The short answer is no, a broker doesn't need keep a list of what topic messages have been published to, it just checks the list of topics each client is subscribed to when a message arrives.

Also if it did keep such a list, how would you decide when to remove a topic from the list, a message may only ever be sent once to that particular topic, would you keep that topic on the list forever?