30

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?

guagay_wk
  • 23,870
  • 50
  • 164
  • 275

1 Answers1

91

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.

ralight
  • 10,473
  • 3
  • 44
  • 58
  • Thanks. Upvoted. You provided the answer for the MQTT specs. Would you happen to know the limits for the node.js mosca MQTT broker? – guagay_wk Dec 30 '15 at 07:36
  • 1
    No, but I imagine the limits are the same. – ralight Dec 30 '15 at 10:09
  • 3
    @Oswin For the 268,435,456 and 65536 byte limits, see the spec. – ralight Jul 01 '16 at 13:12
  • I'd add that one would rarely hit such limits, but that a system should be prepared to handle them if that's a possibility. I would suspect the Mosca broker would stick to the same specs limits. – luis.espinal Oct 24 '18 at 14:45
  • 5
    **References**: For [65KB topic limit](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718016) and the [256MB payload limit](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718023). – Pablo Bianchi Apr 11 '19 at 05:04
  • Don't you mean 65535 (2^16 - 1) and 268,435,455? These are the numbers in the spec and I'm confused why you added 1 to both. – Andy Oct 07 '19 at 16:36
  • what is the difference between payload and message? – Marin Jun 04 '20 at 18:22