Skip to content

MQTT Payload Format Description and Content Type – MQTT 5 Essentials Part 8

by Florian RaschbichlerNOV 12, 20194 min read
TL;DR
MQTT 5 introduces the Payload Format Indicator and Content Type as optional properties in CONNECT and PUBLISH packets. The Payload Format Indicator specifies whether the payload is an unspecified byte stream (0) or UTF-8 encoded (1), while the Content Type uses a UTF-8 string (typically a MIME type) to describe the payload's nature. Together, these MQTT 5 features enable transparent payload description, efficient pre-parsing, and improved interoperability across large-scale systems. Who is this blog for: MQTT implementers, IoT engineers, and solution architects working with MQTT 5 protocol implementations.

Welcome to Part 8 of our MQTT 5 Essentials series. In Part 7, we explored shared subscriptions. In this article, we will focus on Payload Format Indicators, which specify the message content type, ensuring easier, more efficient parsing and interoperability between systems.

What is Payload Format Indicator in MQTT?

The Payload Format Indicator is a fundamental component of any MQTT packet that houses a payload. This includes a CONNECT packet encapsulating a WILL message or a PUBLISH packet. This optional byte value has two possible settings: a 0 indicates an “unspecified byte stream” while a 1 represents a “UTF-8 encoded payload.” When the Payload Format Indicator isn’t provided, it automatically defaults to 0.

The Payload Format Description is optional. It can have the values "1" or "0".

The Payload Format Description is optional. It can have the values "1" or "0".

MQTT Content Type

Similar to the Payload Format Indicator, the Content Type is also optional and can be incorporated in a CONNECT containing a WILL message or any PUBLISH packet. The value for the Content Type must be a UTF-8 encoded string that identifies the payload’s nature. When the Payload Format Indicator is set to 1, ideally, you should have a MIME content type descriptor (though it’s not a hard requirement). A valid UTF-8 String is all you need.

For UTF-8 encoded strings Content Types can be defined.

For UTF-8 encoded strings Content Types can be defined.

Why Describe the Payload Format?

The combined use of Payload Format Indicator and Content Type facilitates a transparent description of the payload content for any application message. This ability sets the stage for creating and defining industry-wide MQTT standards for varied payload formats. MQTT protocol experts view this standardization as the protocol’s natural progression.

Payload Format Description allows pre-parsing without the need to open the payload

Payload Format Description allows pre-parsing without the need to open the payload

Having the payload content description in the headers can prove incredibly beneficial in individual deployments. It ensures every message is correctly processed without delving into the payload itself. Depending on the content type, different messages within a system may need various parsing methods. Moreover, in certain instances, message persistence could hinge on the payload’s specific type. As the content-type definitions hinge on user design, the potential applications of this feature appear boundless.

Summing It Up

The Payload Format Indicator discerns whether a payload is an undefined byte array or a UTF-8 encoded message. When dealing with UTF-8 encoded messages, the sender can use the content type to specify the payload’s nature.

These features set the stage for transparent payload content definitions across large-scale systems and, potentially, entire industries. As the need for pre-parsing actual payloads diminishes, proper message processing can considerably enhance scalability.

Although it’s anticipated that most users will rely on known MIME types to describe the content, they can also use arbitrary UTF-8 Strings.

As we continue to explore all the features of MQTT 5, the next article will cover the Request - Response Pattern.

Sign up for our newsletter to get regular updates. Subscribe to our RSS feed here to stay updated. We encourage you to visit our MQTT Glossary for an in-depth understanding of the essential MQTT terminologies. It will equip you with the necessary vocabulary to grasp the complexities of MQTT and its various versions. Watch the video below that complements the concepts discussed in this article.

Watch the Video

FAQs on MQTT Payload Format Description and Content Type

The format of the MQTT payload is flexible and can contain any data or information that you want to send. MQTT treats the payload as a raw sequence of bytes and does not impose any specific format or structure on it. It can be any arbitrary data, such as strings, JSON, binary data, or even custom formats specific to your application.

The maximum allowable size of a packet sent by the client or server, before any MQTTS or other framing is added, is 256MB.

Yes, you can use JSON as the payload format in MQTT. MQTT treats the payload as a raw sequence of bytes, allowing you to send any data format you prefer, including JSON.

Yes, it is possible for an MQTT broker to implement content-based filtering.

Yes, you can structure metadata within an MQTT payload according to your requirements. MQTT treats the payload as a raw sequence of bytes, allowing you to include any data format, such as JSON, XML, or custom formats, to structure your metadata.

Share this on social media