Forward data to a Tablestore wide table model

更新时间:
复制 MD 格式

Device metadata, such as tags, properties, and statuses, requires high-concurrency updates with low latency, multi-dimensional retrieval, geospatial retrieval, and real-time analysis. The Tablestore wide table engine is a distributed data table suited for storing and updating this metadata. This topic uses a Thing Specification Language (TSL) model data submission topic as an example to show how to forward device data to a Tablestore wide table model.

How it works

image

The data forwarding feature forwards device topic messages to a data table in a Tablestore instance that uses the wide table engine.

The preceding figure shows the following components:

Limits

  • Both the new and previous versions of the data forwarding feature support forwarding data to Tablestore. For an example of how to use the previous version, see Forward data to Tablestore (Previous version).

  • Only IoT Platform instances in certain regions support forwarding data to a Tablestore wide table model. For the supported regions, see Features available in different regions.

  • For the limits on forwarding device messages from an IoT Platform instance, see Limits.

Scenarios

This feature applies to IoT scenarios such as Internet of Vehicles (IoV), smart homes, and industrial IoT. For more information, see Application scenarios of IoTstore.

Prerequisites

  • A data source for the device topic is added. For example, you can create a data source named DataSource and add a TSL model data submission topic for a specific device. For more information, see Add a data source.

  • You have created a Tablestore instance and a data table. For more information, see the Tablestore documentation.

    Important

    If you use an Enterprise Edition instance of IoT Platform, the Tablestore instance must be in the same region as your IoT Platform instance.

Background information

The Tablestore wide table model is similar to the Bigtable or HBase model and suits metadata and big data scenarios. It supports data versions, lifecycle management, auto-increment primary key columns, conditional updates, local transactions, atomic counters, and filters. For more information, see Wide table model.

For more information about how to forward device-reported data from IoT Platform to Tablestore, see IoTstore.

Create a data destination

  1. Log on to the IoT Platform console.

  2. On the Instance Overview tab, find the instance that you want to manage under All Environments and click the instance card.

  3. In the left-side navigation pane, choose Message Forwarding > Data Forwarding.

  4. On the Data Forwarding page, click Go to New Version in the upper-right corner.

    Note

    If you have performed this operation before, you are automatically redirected to the new version of the Data Forwarding page.

  5. Click the Data destination tab, and then click Create data destination.

  6. In the Create Data Destination dialog box, enter a name for the data destination, such as DataPurpose. Configure the parameters as described in the following table and click OK.

    Note

    Only data in the JSON format can be forwarded.

    选择操作

    Parameter

    Description

    Select Operation

    Select Store Data to Tablestore.

    Region

    Select the region where your Tablestore instance is located.

    Instance

    Select a Tablestore instance.

    You can click Create Instance to go to the Tablestore console and create an instance. For more information, see the Tablestore documentation.

    Storage Class

    Select Wide table model.

    Data Table

    Select the Tablestore data table to receive the data.

    You can click Create Data Table to go to the Tablestore console and create a data table.

    Role

    Select a RAM role that grants IoT Platform permissions to write data to Tablestore.

    If no RAM role exists, click Create RAM Role to create a RAM role and authorization policy in the RAM console. Create a RAM role.

Configure and start a parser

  1. Create a parser, such as DataParser. For more information, see Step 1: Create a parser.

  2. On the Resolver Details page, associate the data source.

    1. In the configuration wizard, under Data Source, click Associate Data Source.

    2. In the dialog box, select DataSource from the Data Source drop-down list and click OK.

  3. On the Resolver Details page, you can associate data destinations.

    1. In the configuration wizard, click Data Destination. Then, in the upper-right corner of the Data Destination list, click Associate Data Destination.

    2. In the dialog box that appears, from the Data Destination drop-down list, select DataPurpose and click OK.

    3. In the data destination list, find the Data Destination ID and record it. For example, 1000.

      You will need this Data Destination ID in the parsing script.

  4. On the parser details page, click the Parser Script tab.

  5. In the script editor, enter a parser script.

    The parser script uses a JavaScript-like syntax. For more information, see Script syntax.

    For more information about function parameters, see Function list.

    // Use the payload() function to obtain the message that is reported by the device and convert the message to the JSON format.
    var data = payload("json");
    // Obtain the values of the reported properties.
    var h = data.items.Humidity.value;
    var t = data.items.Temperature.value;
    // Add the primary keys deviceName and id to the table. In the writeTableStore method, you can write the temperature and humidity values to the corresponding columns in the column:value format.
    writeTableStore(1000, {"deviceName":deviceName(), "id":timestamp(), "temperature":t, "humidity":h});
  6. Click Test. Select a product and a device, and then enter the topic and payload data as prompted to test the script.

    The following figure shows sample parameters:调试示例

    The following output indicates that the script ran successfully.

    调试结果

  7. Click Publish.

  8. Return to the Resolver tab on the Data Forwarding page and click Start for the DataParser resolver.

What to do next

  1. In the IoT Platform console, click the destination Enterprise instance to view the device status and message forwarding logs. For more information, see IoT Platform logs.

  2. After the data is pushed, go to the Data Management tab of the receiving data table in Tablestore to verify that the data is received.

    数据管理

Operation example

Device metadata ingestion solution

References