I want to connect a client which will monitor all the topics of the broker to respond to the events when I don't know what are names of topic.
Q- Can I get list of all topics on a broker? A- Not unless you subscribe to all topics and scan them.
When a client subscribes to a topic, it can subscribe to the exact topic of a published message or it can use wildcards to subscribe to multiple topics simultaneously. A wildcard can only be used to subscribe to topics, not to publish a message.
To receive messages on topics of interest, the client sends a SUBSCRIBE message to the MQTT broker. This subscribe message is very simple, it contains a unique packet identifier and a list of subscriptions. Packet Identifier The packet identifier uniquely identifies a message as it flows between the client and broker.
Click OK and then click on the Connect button. MQTT. fx will establish a connection with the local Mosquitto server. Notice that the Connect button is disabled and the Disconnect button is enabled because the client is connected to the MQTT server.
Subscribing to #
gives you a subscription to everything except for topics that start with a $
(these are normally control topics anyway).
It is better to know what you are subscribing to first though, of course, and note that some broker configurations may disallow subscribing to #
explicitly.
You can use mosquitto_sub
(which is part of the mosquitto-clients
package) and subscribe to the wildcard topic #
:
mosquitto_sub -v -h broker_ip -p 1883 -t '#'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With