You can use the data forwarding feature of the rules engine to forward device data to an MNS topic. Your business server subscribes to the messages of the topic. This implements high-performance message transmission between your business server and devices.This article 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 MNS is created in a region that supports data forwarding to MNS.
    Supported instances Supported regions
    Enterprise Edition instances: Standard and Video
    • China (Shanghai)
    • Japan (Tokyo)
    Public instances
    • China (Shanghai)
    • Singapore
    • Japan (Tokyo)
    • Germany (Frankfurt)
    • US (Silicon Valley) and US (Virginia)
  • A data source named DataSource is created and a TSL communication topic is added the data source. For more information, see Create a data source.
  • An MNS topic is created. A subscription whose Push Type parameter is set to HTTP or Queue is created for the topic. For more information, see the MNS documentation.
    Important If you use an IoT Platform instance of the Enterprise Edition, the region where the MNS topic resides must be the same as that of the IoT Platform instance.

Background information

For more information about the data forwarding process, see Data forwarding procedure.

Usage notes

You can use the new version or old version of the data forwarding feature to forward data to MNS. For more information about how to use the old version of the data forwarding feature, see Use the new version of the data forwarding feature to forward data to MNS.

Create a data destination

  1. Log on to the IoT Platform console.
  2. On the Overview page, find the instance that you want to manage and click the instance name to go to the Instance Details page.
    Important Enterprise Edition instances are available in the China (Shanghai) and Japan (Tokyo) regions. If the Enterprise Edition instances are unavailable in the region that you select, skip this step.
    Overview
  3. In the left-side navigation pane, choose Rules Engine > Data Forwarding.
  4. Optional:On the Data Forwarding page, click Go to New Version in the upper-right corner to go to the new version.
    Note If you have performed this step, the Data Forwarding page of the new version appears after you choose Rules > Data Forwarding.
  5. Click the Data Destination tab. On this tab, click Create Data Destination.
  6. In the Create Data Destination dialog box, enter a data destination name. In this example, enter DataPurpose. Set the parameters and then click OK.
    Parameter Description
    Operation Select Send Data to MNS.
    Region Select a region where MNS runs.
    Topic Select an MNS topic that is used to receive data.

    MNS 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 MNS through only the HTTP or queue method.

    To create an MNS topic and subscription in the MNS console, click Create Topic. For more information, see the MNS documentation.

    Role Authorize IoT Platform to write data to MNS.

    If no RAM roles exist, click Create RAM Role to go to the Resource Access Management (RAM) console, create a RAM role, and then grant permissions to the RAM role. For more information, see Create a RAM role.

Configure and start a parser

  1. Create a parser named DataParser. For more information, see Create a parser.
  2. On the Parser Details page, associate the parser with the created data source.
    1. In the Data Source step of the wizard, click Associate Data Source.
    2. In the dialog box that appears, select DataSource from the Data Source drop-down list, and then click OK.
  3. On the Parser Details page, associate the parser with the created data destination.
    1. Click Data Destination in the wizard. In the Data Destination section, click Associate Data Destination.
    2. In the dialog box that appears, select DataPurpose from the Data Destination drop-down list, and then click OK.
    3. 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.
  4. On the Parser Details page, click Parser.
  5. In the code editor, enter a script. For more information about how to write a script, see Sample script.
    For more information about the function parameters, see Functions.
    // Use the payload() function to obtain the data that is submitted by devices and convert the data by using the JSON format. 
    var data = payload("json");
    // Forward submitted TSL data. 
    writeMns(1000, data)
  6. 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. Debugging example

    The following result indicates that the script is implemented.

    Running result
  7. Click Publish.
  8. 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.