MQTT and Mosquitto FAQs


Q- Do all clients need a unique client name?

A- Yes .The client name is used by the MQTT broker to identify the client.

This is necessary when using persistent connections (clean session flag False), as the broker needs to store messages for the client when the client isn’t connected.

Q- What are clean sessions?

A- When a client connects to a broker it can set a clean session flag to indicate to the broker that is doesn’t need to retain any session information for this client after it has disconnected. In the clean session flag is set to False then the broker will remember the topics that the client subscribed to and also will store messages sent to that topics for the the client so that when the client re-connects it will receive those messages. This is however dependent on QOS settings. See MQTT Clean Sessions and QOS Examples

Q- What happens to messages that get published to topics that no one subscribes to?

A- They are discarded by the broker.

Q-How can I find out what topics have been published?

A- You can’t do this easily as the broker doesn’t seem to keep a list of published topics as they aren’t permanent.

Q- Can I subscribe to a topic that no one is publishing to?

A- Yes

Q- Can I publish and subscribe using the same client connection?

A- Yes

Q- Are messages stored on the broker?

A- Yes but only temporarily. Once they have been sent to all subscribers they are then discarded unless retained. But see next question.

Q- What are retained messages?

A- When you publish a message you can have the broker store the last  published message. This message will be the first message that new subscribers see when they subscribe to that topic.  MQTT only retains 1 message. See Retained Messages by example

Q- What is a last will message?

A– It is a message sent by a broker when an MQTT client gets disconnected abnormally- See Last Will and Testament by example

Q- What is MQTT-SN?

MQTT-SN stands for MQTT for sensor networks. It uses UDP instead of TCP and isdesigned to work over UDP, ZigBee and other transports. See MQTT-SN working Notes.

Q- Why is there no MQTTv4?

This is because the protocol identifier for MQTTv3.1.1 used the value 100 as the value 011 was already taken by version 3.0. So the next available was 101 which is 5 decimal.

Q -Does the client or the broker choose the protocol version to use?

The client indicates the protocol version to use on the connection as part of the connect message.

Q- What are Inflight Messages

MQTT offers three QOS settings -0,1,2 as described in the understanding QOS tutorial.

QOS levels 1 and 2 require an acknowledgement from the MQTT broker.

A client can decide not to wait for an acknowledgement from the broker before it sends the next message, in which case the previous unacknowledged message is “inflight”.


Can Inflight messages be controlled?

Yes both the Mosquitto broker and the paho python client let you change the number of inflight messages that are allowed.

On Python we set this before we establish the connection using

inflight= an integer e.g. 4

Mosquitto Broker

Q- How do I delete, clear or remove all retained messages on the Mosquitto broker.

A- If you’re not using the persistent database then  easiest way is to stop and restart mosquitto. Otherwise you will need to subscribe to all topics to check and clear the retained messages. You can use my Python script to do this. However this is not recommended on a busy broker.

Q-How do I delete a topic or topic hierarchy?

A- You can’t delete a topic from the broker. Topics are created by the clients. Topics are automatically remove from a broker when no client is subscribed to them or the broker isn’t holding a topic open for a client that has a persistent connection. See Understanding topics and MQTT clean sessions.

Q- On the Mosquitto broker was does the persisten storage Setting do?

This allows you to store session state, retained messages and undelivered messages in the event of a broker shut down.

Q- What user account does the mosquitto broker use?

Mosquitto uses the mosquitto user.


Please rate? And use Comments to let me know more