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
- MQTT v 5.0 New Features Overview
- Understanding And Using MQTT v5 Request Response
- MQTTv5 Properties by Message Type
- MQTTv5 Shared Subscriptions
- MQTTv5 Topics and Topic Aliases
- Examining MQTTv5 User Properties
- MQTTv5 CONNECT and CONNACK Messages -Overview
- MQTTv5 Clean Start (Clean Sessions) and Session Expiry
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) .
The command is
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.
Hi Steve I tried but its logging only 1000 messages. any other methods?…
No as I know what version of mosquitto are you using and can you try on another broker?
This is the version which i am using [Eclipse Mosquitto MQTT v5/v3.1.1 broker]
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?
Mosquitto version 2.0.15
Mosquitto is an MQTT v5.0/v3.1.1/v3.1 broker.
I will try it on my broker. Can you send me you mosquitto.con file using the ask-steve page
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.
Yes you can. have you seen this
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?
Sorry no idea as I don’t use ignition
Thanks steve for responding
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.
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?
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.
It depends on the client software and hardware as there are no limits in the protocol.
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
Sorry, I thought you delete my question
Can I limit message count for each user in each day?
Example only publish 10 messages in a day
Not that I know. I will look again when I’m feeling a bit sharper
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?
yes I want to calculate the size before sending and receiveing
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.
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.
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?