This topic describes mappings between the message structures and properties involved in interaction with Message Queue for MQTT by using the Message Queue for Apache RocketMQ SDK, helping you better understand and use Message Queue for MQTT and Message Queue for Apache RocketMQ.

Message Queue for MQTT is a gateway service that is intended for mobile devices. Message Queue for MQTT can interact with other Alibaba Cloud services such as Message Queue for Apache RocketMQ based on data interaction rules. For more information, see Manage rules.

If you use Message Queue for MQTT independently, ignore the mappings described in this topic and observe the Message Queuing Telemetry Transport (MQTT) protocol.

For more information about Message Queue for MQTT, see What is Message Queue for MQTT? and Terms.

Message structure mappings

Message Queue for MQTT and Message Queue for Apache RocketMQ are messaging systems that are based on the publish-subscribe model and have similar concepts. The following figure shows the differences in the major concepts and mappings between them.

Message structure

Message Queue for MQTT supports multi-level topics, whereas Message Queue for Apache RocketMQ supports one-level topics, as shown in the preceding figure. Therefore, a level-1 topic in Message Queue for MQTT is mapped to a topic in Message Queue for Apache RocketMQ, and level-2 and level-3 topics in Message Queue for MQTT are mapped to the message properties in Message Queue for Apache RocketMQ.

The Message Queue for Apache RocketMQ protocol supports messages with custom properties, whereas the MQTT protocol does not support properties. However, part of the information in Message Queue for MQTT is mapped to message properties in Message Queue for Apache RocketMQ. This facilitates tracing of the headers and device information in the MQTT protocol and allows users of the Message Queue for Apache RocketMQ SDK to retrieve such information.

Note For information about how to configure mappings from properties in Message Queue for Apache RocketMQ to parameters in Message Queue for MQTT, see the table in Property mappings.

Message Queue for Apache RocketMQ and Message Queue for MQTT use the data serialization results of your service messages as the payload. Message Queue for Apache RocketMQ and Message Queue for MQTT do not further encode and decode the service messages.

Property mappings

The following table lists the property mappings supported between Message Queue for MQTT and Message Queue for Apache RocketMQ. You can set or retrieve information by reading and writing these properties during interaction between applications that use the Message Queue for Apache RocketMQ and Message Queue for MQTT SDKs.

For more information about QoS, cleanSession, topics, and client IDs, see Terms.

Message Queue for MQTT parameter Message Queue for Apache RocketMQ property key Valid property value Description
QoS qoslevel 0, 1, and 2

This property can be set when Message Queue for Apache RocketMQ sends messages to Message Queue for MQTT. If it is not set, the default value 1 is used.

Message Queue for Apache RocketMQ can directly read the QoS parameter from the messages that are sent from Message Queue for MQTT.

cleanSession cleansessionflag true and false

This property can be set when Message Queue for Apache RocketMQ sends P2P messages to Message Queue for MQTT clients. If it is not set, the default value true is used.

This property cannot be set for other message types. Message Queue for Apache RocketMQ can directly read the cleanSession parameter from the messages that are sent from Message Queue for MQTT.

Subtopic mqttSecondTopic A string that indicates a specific subtopic

This property can be set when a subtopic is required to filter the messages that Message Queue for Apache RocketMQ sends to Message Queue for MQTT clients. If it is not set, the default value null is used.

Message Queue for Apache RocketMQ can directly read the subtopic from the messages that are sent from Message Queue for MQTT.

Topic in messages received on a client mqttRealTopic The sub-level string that services expect message-receiving clients to display

This property can be set when a Message Queue for MQTT client is expected to display the specified subtopic name after it receive messages from Message Queue for Apache RocketMQ. This property is typically applied to P2P messages. If it is not set, P2P messages use a fixed topic name by default.

The messages that Message Queue for MQTT sends to Message Queue for Apache RocketMQ do not contain the corresponding parameter.

clientId clientId A string that indicates a specific client ID This property cannot be set. When a Message Queue for MQTT client sends a message to Message Queue for Apache RocketMQ, the clientId parameter is used to trace the ID of the client.