Reputation: 28030
I am using the node.js mosca MQTT broker for some internet of things (iot) application.
https://github.com/mcollina/mosca
What is the maximum message length that a topic can receive for the mosca broker? What are the factors that constrain the message length?
If I want to increase the message length, is there a configuration parameter I can modify or which part of the code can I change?
Upvotes: 34
Views: 58155
Reputation: 4357
The answer isn't completely straightforward, unfortunately.
I'll assume you're referring to the length of the payload, which is the component of an MQTT application message that is generally used to encode data.
The anatomy of an MQTT consists of a fixed size header, a variable length header, and a payload. The fixed size header is used to indicate what kind of message is being sent (despite the name, it is not always the same size). The variable length header is used to convey information specific to each message. Section 2.3 of the MQTT 5 standard refers to the payload as the "final part of the packet" - so it's everything after the variable length header.
The size of the message is indicated in the fixed size header. This field can reach up to 268,435,455 (see section 1.5.5 and 2.1.1). However, this is not the same as the maximum size of the payload, because it also includes the variable length header.
Before I try to answer the question more specifically, I'll assume that you're talking about the maximum size of a payload in an MQTT "PUBLISH" message, which is what you use when you're publishing telemetry and what not.
For a PUBLISH packet, the variable length header consists of:
The topic name, although theoretically can take up to 2 + [0:65535]
, is usually pretty short. The packet identifier is 2 bytes long, always. The properties table can take up a wide range of sizes, so I'm not going to try and write that out as an expression.
See section 3.3.2 for this info.
So the maximum size of the payload for a MQTT publish message would be 268,435,455 - (2 + 1) - 2 - 1
, assuming the topic length is one character and there are no properties associated with the message.
Disclaimer: I have not tested this, and there's likely a soft limit defined by the broker you're using.
The sections I am referencing are from the version 5 spec: http://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html
Upvotes: 4
Reputation: 11608
It's not entirely clear what you're asking here, so I'll answer both possibilities.
The length of the actual topic string is at most 65536 bytes. This is a limit imposed by the mqtt spec, you can't change it. It is also worth noting that the topic is encoded with utf-8, so you may have less than 65536 characters available.
The payload of the message is limited to 268,435,456 bytes. Again, this is defined by the spec.
If you are routinely approaching either of these limits you should be thinking about whether what you are doing is sensible.
Upvotes: 106