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.
You can set message size restrictions or limits in two places:
- Mosquitto MQTT broker
- MQTT Client (MQTT v5 only)
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.
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