MQTT Client and Mosquitto Broker Message Restrictions With Examples

The MQTT protocol allows messages with a maximum size of 268435455 bytes approx 260MB.

This is obviously a very large message size and one that most brokers,especially public brokers, will restrict.

Message Restrictions

You can set message size restrictions or limits in two places:

Broker Message Size Limits

This is obviously broker dependent.

The Mosquitto Broker has a maximum messages size limit. that affects all packets and clients.

However MQTTv5 clients will be informed of this limit when connecting.


Here is an example of setting the message_size_limit to 200 bytes.

mos_conf_message size

When the broker receives a message that exceeds that size it drops the packet and returns a reason code (v5 only screen shot below).

The publishing client can check the Puback to determine if the publish succeeded (MQTTv5).

MQTT Client Message Size Limits (MQTTv5)

The maximum message size that the client will accept is set in the connect packet and tells the server not to send packets that exceed this size.

In the python client this is how it is set:

client = MQTTClient(client_id,maximum_packet_size=100)

The above sets the maximum size that the client will accept to 100 bytes. If a publisher sends a packet that exceed this size it is discarded.

The screen shot below show two clients connect to a broker receiving messages on the topic test,

The client testclient has a message size limit set of 100 bytes and the publisher sends a message that exceeds this:


Notice the subscriber with no limits on the connection (mosqsub|11704-ws6) receives the message.

The publishing client doesn’t know that a subscriber has rejected the message due to size constraints.

Maximum Queued Messages

This usually applies to QOS 1 and 2 messages but can also apply to QOS 0 messages if the queue_qos0_messages Option is set to true.(default is false).

In the event of a connection failure then messages are held in the queue until the limit has been reach and then new messages are discarded.

The queue appears to be a client queue not a broker wide queue.

Related Tutorials and Resources

Please rate? And use Comments to let me know more


  1. Hi Steve, My Message is getting Queued Up to 1000 messages is there any possible to increase , even though I used max_queued_messages_set(65000) .

    1. The command is
      max_queued_messages count

      1000 is the default so it looks like your setting is being ignored .Assume you have restarted the broker.
      Try setting it at 10 and testing to make sure the setting is working.

          1. That isn’t the version. When you start it on the command line you should see the version number. Do you have another version to try?

          2. I will try it on my broker. Can you send me you mosquitto.con file using the ask-steve page

  2. I have a noob question for you. If I have a click plc which can use the mqtt protocol can I use mqtt to affect (turn on or off) control relays inside of the click plc program? ie: send a message to the click plc it reads an instruction message say on or off and changes the bit to on or off. I am new to mqtt and IoT.

  3. Hi steve

    I’m using ignition scada as broker and connecting my mosquitto client to ignition. Is there any command to get edge details(num of edges and their names etc..) in broker?

  4. Hi Steve,

    I really appreciate your documentation on Mosquitto MQTT. I have a mosquitto broker on AWS and different external MQTT publisher and subscriber. When I publish a message the subscriber is not receiving it and when I disconnect and subscribe it again it is receiving the new message. I use the same username and password for both publisher and subscriber. Do you think this is a problem? If so how to over come it as we cannot create a new username for new subscriber. Note: I am using different client ID for publisher and subscriber.


    1. There is nothing in mqtt that stops you using the same username password on multiple clients but AWS might. However I doubt it. When you disconnect do you disconnect both clients and when you reconnect do you reconnect both clients are you setting the retain flag on publish?

  5. Hi Steve,

    I there a limit on number of messages that a client can receive.
    e.g. lets say I have 300 topics and on each topic, message is published every 250ms.
    Now I create a mqtt-client and subscribe to all topics. Will the client be able to receive all message.
    I am seeing that all messages are not received by the client. The message size is 600 bytes.

  6. Steve, why do you delete my comment?
    If my question is wrong, please say to me
    I love you and your site
    That’s an insult to me

  7. Hi
    Can I limit message count for each user in each day?
    Example only publish 10 messages in a day

        1. Hi
          You will need to get the payload into bytes format before sending and just take the length. How you do that depends on the language you are using. On receive the message is usually in byte format and you just take the length.

  8. What about message frequency limits? What happens when I send MQTT messages to the broker at 100Hz or 200Hz in a LAN-Network?

  9. How to see the maximum message length/ check whether messages are blocked when Mosquitto is installed on a Raspberry Pi?
    Which lines do I need to run in the terminal?
    Thanks for the great explanations! 🙂

    1. When you mean check whether messages are blocked do you mean from the broker console or client?

Leave a Reply

Your email address will not be published. Required fields are marked *