Search code examples
mqttmosquitto

What happens if I subscribe to a MQTT topic which has never been published to?


My understanding is a topic is not something that really exists until a message is published to.

Is it possible for a client to subscribe to a topic that the broker can see has never been published to? And may not be published to for a while (say a few minutes)?


Solution

  • The effect of subscribing to a topic that has never been published to is the same as subscribing to a topic that has been published to (unless there is a message with retain set on that topic).

    Your client will wait for messages that are published to that topic. It can wait for a message as long as the client and the broker run and stay connected.

    Think of it this way: If a client could not subscribe to a topic that has never been published to, then the first message published on a topic would never reach any clients.