19

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.

Lii
  • 11,553
  • 8
  • 64
  • 88
gillesC
  • 677
  • 1
  • 5
  • 23
  • What exactly are you trying to achieve here? Subscribing to a huge list of topics will cause more overhead in the broker (as it has to check everything in the list) vs just checking '#' which matches everything. – hardillb Mar 02 '17 at 16:00
  • I'm not saying I want to subscribe to everything. I'm just seeking to request all published topics. For instance, the broker could just response with an string array containing all the published topics. I've edited my question to better reflect my intentions. – gillesC Mar 02 '17 at 16:17
  • Did you get the solution for your problem. I am also required to publish message in a particular topic. If you got the solution please share me... – v teja Apr 20 '22 at 12:49

6 Answers6

6

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.

Gambit Support
  • 1,432
  • 1
  • 7
  • 17
4

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
Asoul
  • 996
  • 1
  • 10
  • 22
1

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?

hardillb
  • 54,545
  • 11
  • 67
  • 105
1

Yes, subscribing to '#' has it's problems, and the author asked for a different solution.
But on smaller (less active) brokers it's often a viable solution.

For example, http://mqtt-explorer.com/ offers a nice tree view of the topics received.
So subscribing to '#' for a limited time can provide a good overview of the active topics.

Thyraz
  • 2,412
  • 2
  • 21
  • 23
0

A workaround, not perfect, but still good in some cases:

Use the mosquitto_sub client executable in debug mode, subscribed to all topics. Collect info for 1 hour or whatever you think is good enough, and parse the output to extract the topics.

Eg: these guys http://www.mqtt-dashboard.com/ have a lively public mqtt server but there is no indication about the topics other people send data too (and I wanted to test only the subscribe part of the protocol, no data to publish). As a starting point, I found on reference on the net that their topics start with "test/".

Running this:

./mosquitto_sub -h broker.hivemq.com -t test/# -d

allowed me to see lots of live topics, albeit probably not all of them (even if let it open for one full day).

Nelu Bidonelu
  • 185
  • 2
  • 4
0

In order to check all existing topics in the broker, you can type in the Zenmap network scanner nmap -p 1883 --script mqtt --subscribe . This command will display all topics with their names.

onsze
  • 1