2

I have a HiveMQ MQTT server that I am running. When I connect using MQTT explorer I can see all of the topics and sub-topics. However, I can't seem to find a way to recreate this with the HiveMqtt Java SDK. I can subscribe to /# but that only works if the device sends a message after subscribed. I want to on boot cache all of the currently available topics.

Is this possible so I don't have to manually maintain a list?

2
  • 1
    Topics should not start with a leading / this just adds a extra null to the topic tree Commented Sep 2, 2024 at 7:07
  • You are correct the actual line is .topicFilter(rootTopic + "/#") Commented Sep 2, 2024 at 13:07

1 Answer 1

1

There is no topic list, brokers don't work that way.

Topics only exist on published messages, brokers don't have a "list of topics".

What brokers do have is a list of topic patterns, one for every subscription, but these can include wildcards that can match many infinitely many different topics.

The same applies to the ACL that controls which topics a client can publish to, this is also a list of topic patterns that can include the same wildcards.

Also just as a side note, just because a message has once been published to a topic doesn't mean that another ever will be.

Any client that appears to show a topic tree at start up must be caching a list of previously seen messages and updating it as new messages are published. This might look like a "full topic tree" if the applications making use of the broker publish retained message as all those messages would be delivered on connection.

2
  • Then how does MQTTExplorer do it when it first connects? I think there is a hiveMQ endpoint so I will post the solution once I figure it out. It isn't cached because it happens on the first connect even after blowing away the app and clearing its data Commented Sep 2, 2024 at 13:05
  • There is no list, and that would mean that MQTT Explorer has some HiveMQ specific code. It can only be subscribing to '#' and populating the list with the initial messages it sees (e.g. the retained messages) and/or caching previous values. Commented Sep 2, 2024 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.