This topic describes the message properties in Message Queuing Telemetry Transport (MQTT) 5.0 supported by IoT Platform.
Feature description
Two new message properties are introduced in MQTT 5.0: Payload Format Indicator and Content Type.
The properties can be included in a PUBLISH message or will message.
Payload Format Indicator
Payload Format Indicator occupies only one byte. Valid values:
1: specifies that the payload is UTF-8 encoded character data.
0: specifies that the payload is encoded in an unspecified format. For example, the payload is binary data.
Content Type
Content Type stores a string that specifies the type of message content. You can set this property to Multipurpose Internet Mail Extensions (MIME) types such as text/plain for text files. You can also configure this property based on your business requirements. The specified content type cannot be modified during message forwarding.
If you want to modify the content type when you forward a message, you can configure User Property because only this property is valid during message forwarding.
Scenarios
Message properties improve interoperability and configuration transparency in cross-system messaging. The properties provide the following benefits:
Compatibility with payload of various encoding formats and content types.
Smooth messaging process in which the intermediate nodes do not need to parse the payload.
Compatibility with payload of various encoding formats and content types
In MQTT-based messaging, data in a topic must use the same encoding format and content type. However, IoT devices keep evolving and the devices may use different types of payload. In this case, you can use message properties to describe the message payload, as shown in the following figure.
Device 1: publishes JSON strings.
Device 2: publishes Protocol Buffers (Protobuf) binary data.