You can use the data forwarding feature of the rules engine to forward device data to a Simple Message Queue (SMQ, formerly MNS) topic. Your business server can subscribe to this topic to obtain the messages from devices. This implements high-performance message transmission between your business server and devices. This topic describes the data forwarding process. In this example, a Thing Specification Language (TSL) communication topic is used as the source topic.
Prerequisites
An IoT Platform instance whose data can be forwarded to SMQ is created in a region that supports data forwarding to SMQ. For more information, see Regions.
A data source named DataSource is created and a TSL communication topic is added to the data source. For more information, see Create a data source.
An SMQ topic is created. A subscription whose Push Type parameter is set to HTTP or Queue is created for the topic. For more information, see Create a topic.
ImportantIf you use an IoT Platform instance of the Enterprise Edition, the region in which the SMQ topic resides must be the same as that of the IoT Platform instance.
Background information
For more information about the data forwarding process, see the Data forwarding procedure section of the "Forward data to SMQ" topic.
Usage notes
You can use the new or previous version of the data forwarding feature to forward data to SMQ. For more information about how to use the previous version of the data forwarding feature, see Forward data to SMQ.
Create a data destination
- Log on to the IoT Platform console.
On the Overview page, click All environment. On the All environment tab, find the instance that you want to manage and click the instance ID or instance name.
- In the left-side navigation pane, choose .
In the upper-right corner of the Data Forwarding page, click Go to New Version to go to the new version.
NoteIf you have performed this step, the Data Forwarding page of the new version appears after you choose Message Forwarding > Data Forwarding.
- Click the Data Destination tab. On this tab, click Create Data Destination.
In the Create Data Destination dialog box, enter a data destination name. In this example, DataPurpose is used. Configure the parameters and click OK.
Parameter
Description
Operation
Select Send Data to SMQ.
Region
Select a region where SMQ runs.
Topic
Select an SMQ topic that is used to receive data.
SMQ sends received messages to a subscription of the topic. The Push Type parameter value of the subscription is HTTP or Queue. You can subscribe to messages that IoT Platform pushes to SMQ through only the HTTP or queue method.
To create an SMQ topic and subscription in the SMQ console, click Create Topic. For more information, see the SMQ documentation.
Role
Authorize IoT Platform to write data to SMQ.
If you do not have Resource Access Management (RAM) roles, click Create RAM Role to go to the RAM console, create a RAM role, and then grant permissions to the role. For more information, see Create a RAM role.
Configure and start a parser
Create a parser named DataParser. For more information, see Create a parser.
On the Parser Details page, associate the parser with the created data source.
In the Data Source step of the wizard, click Associate Data Source.
In the dialog box that appears, select DataSource from the Data Source drop-down list, and then click OK.
On the Parser Details page, associate the parser with the created data destination.
Click Data Destination in the wizard. In the Data Destination section, click Associate Data Destination.
In the dialog box that appears, select DataPurpose from the Data Destination drop-down list, and then click OK.
In the Data Destination section, view and save the data destination ID. In this example, the ID is 1000.
When you write the parser script, you must use the data destination ID.
- On the Parser Details page, click Parser.
In the code editor, enter a script. For more information about how to modify a script, see Script syntax.
For more information about function parameters, see Functions.
// Use the payload() function to obtain the data that is submitted by devices and convert the data to JSON-formatted data. var data = payload("json"); // Forward submitted TSL data. writeMns(1000, data);
Click Debugging. In the dialog box that appears, select a product and a device, specify a topic, and then enter payload data to check whether the script runs as expected.
The following figure shows the parameters.
The following result indicates that the script runs as expected.
- Click Publish.
Go to the Parser tab of the Data Forwarding page. Find the DataParser parser and click Start in the Actions column to start the parser.