Data inbound rules route messages from other Alibaba Cloud services to ApsaraMQ for MQTT clients over the MQTT protocol. You can call the API operations of the Alibaba Cloud services to send data to the ApsaraMQ for MQTT clients. Currently, only ApsaraMQ for RocketMQ is supported as a data source.

How data inbound rules work
A data inbound rule bridges a RocketMQ topic to an MQTT topic. After you enable the rule, messages published to the RocketMQ topic are automatically forwarded to the specified MQTT topic and delivered to subscribed MQTT clients.
MQTT supports multi-level topics (for example, a/b/c), while RocketMQ supports only single-level topics. To bridge this gap, the level-1 MQTT topic maps to the RocketMQ topic, and deeper levels map to RocketMQ message properties. For the complete mapping logic, see Message structure mappings between ApsaraMQ for MQTT and ApsaraMQ for RocketMQ.
Prerequisites
Before you begin, make sure that you have:
An ApsaraMQ for MQTT instance with kernel version V3.x.x
An ApsaraMQ for RocketMQ 4.0 instance in the same region as the MQTT instance
A topic created on both the RocketMQ and MQTT instances
View the kernel version of an ApsaraMQ for MQTT instance in the instance list or on the Instance Details page in the ApsaraMQ for MQTT console.
Usage notes
When an ApsaraMQ for RocketMQ broker is being updated, MQTT clients may receive messages with increased latency through data inbound rules. For scheduled maintenance windows, see Notice List.
Rule components
Each data inbound rule consists of three parts:
| Component | Description | Required |
|---|---|---|
| Basic information | Rule ID (globally unique, immutable after creation), description, status (enabled or disabled), and rule type. | Yes |
| Rule source | The ApsaraMQ for RocketMQ instance and topic from which messages are pulled. | Yes |
| Rule destination | The ApsaraMQ for MQTT topic to which messages are delivered. | Yes |
Create a data inbound rule
Log on to the ApsaraMQ for MQTT console. In the left-side navigation pane, click Instances.
In the top navigation bar, select the region of the target instance. Click the instance name to open the Instance Details page.
In the left-side navigation pane, click Rules. In the upper-left corner of the Rules page, click Create Rule.
In the Configure Basic Information step, set the following parameters and click Next.
Parameter Example Description Rule ID 111111 A globally unique identifier. Supports letters, digits, hyphens (-), and underscores (_). Must contain at least one letter or digit. Length: 3-64 characters. Auto-truncated if longer. Cannot be changed after creation. Description migrate from rocketmq A text description for the rule. Status Enable Whether to activate the rule immediately. Valid values: Enable, Disable. Rule Type Data Inbound Select Data Inbound to import data from other Alibaba Cloud services into ApsaraMQ for MQTT. In the Configure Rule Source step, specify the data source and click Next.
Parameter Example Description Source Service Type Message Queue for Apache RocketMQ The cloud service from which data is forwarded. Only ApsaraMQ for RocketMQ is supported. Message Queue for Apache RocketMQ Instance MQ_INST_13801563067\*\*\*\*\*\_BbyOD2jQ The RocketMQ instance ID. Must be in the same region as the MQTT instance. Topic Topic A The RocketMQ topic whose messages are forwarded to ApsaraMQ for MQTT. In the Configure Rule Destination step, specify the target MQTT topic and click Create.
Parameter Example Description Topic Topic B The MQTT topic to which data is delivered. Because MQTT supports multi-level topics and RocketMQ does not, a level-1 MQTT topic maps to the RocketMQ topic, and other levels map to RocketMQ message properties. For details, see Message structure mappings between ApsaraMQ for MQTT and ApsaraMQ for RocketMQ.
After the rule is created, it appears on the Rules page.
Manage existing rules
On the Rules page, find the target rule in the rule list. In the Actions column, choose More and select an operation:
| Operation | Steps |
|---|---|
| Edit a rule | Select Edit. On the Edit Rule page, modify the parameters as needed. All parameters except Rule ID can be changed. Click Save in the Configure Rule Destination step to apply the changes. |
| Delete a rule | Select Delete. In the confirmation dialog box, click OK. |
| Enable a rule | Select Enable. In the confirmation dialog box, click OK. |
| Disable a rule | Select Disable. In the confirmation dialog box, click OK. |
Related topics
To export data from ApsaraMQ for MQTT to other Alibaba Cloud services, see Data outbound rules.
For the complete message mapping logic between MQTT and RocketMQ, see Message structure mappings between ApsaraMQ for MQTT and ApsaraMQ for RocketMQ.
To export client connect and disconnect events, see Export status events of ApsaraMQ for MQTT clients.