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:
- 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
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
Hi I haven’t deleted it. haven’t got around to reading it as I have got the flu and the moment
Rgds
Steve
Sorry, I thought you delete my question
Hi
Can I limit message count for each user in each day?
Example only publish 10 messages in a day
Thanks
Hi
Not that I know. I will look again when I’m feeling a bit sharper
Rgds
Steve
Thanks
hi steve, its any possible to get payload size(320bytes) in paho client ?
Not sure what you mean. Do you want to calculate the size before sending?
Rgds
Steve
yes I want to calculate the size before sending and receiveing
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.
Rgds
Steve
What about message frequency limits? What happens when I send MQTT messages to the broker at 100Hz or 200Hz in a LAN-Network?
As far as I’m aware this is not configurable.
Rgds
Steve
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! 🙂
When you mean check whether messages are blocked do you mean from the broker console or client?
Rgds
Steve