EMQX data ingestion

Updated at:

After you send simulated temperature and humidity data to the EMQX Platform over the Message Queuing Telemetry Transport (MQTT) protocol, you can use the EMQX Platform data integration feature to forward the data to Tablestore.

Prerequisites

  • EMQX Platform

    EMQX Platform is an MQTT message middleware product from EMQ for the Internet of Things (IoT) domain. As the world's first fully managed MQTT 5.0 message cloud service, EMQX Platform provides a one-stop MQTT messaging service in dedicated, isolated environments. EMQX Platform helps you quickly build industry applications for the IoT domain and easily implement data collection, transmission, computation, and persistence for your IoT data.
    • You have created a dedicated EMQX cluster on the EMQX Platform.

    • You have created a VPC peering connection with the Alibaba Cloud platform to establish network connectivity between VPCs.

      Note

      If you want to connect to resources using a public IP address, you must enable NAT Gateway.

    • You have downloaded the MQTT X tool to simulate sending data later.

  • Tablestore

    • You have activated the Tablestore service, created a Tablestore instance, created a time series table named temp_hum, and created a timeline with the metric name cloud. For more information, see Use the time series model in the console.

    • You have attached a VPC that has an established peering connection with the EMQX Platform to the instance. For more information, see Attach a VPC.

    • You have created an AccessKey pair, which includes an AccessKey ID and an AccessKey secret, for your Alibaba Cloud account or for a Resource Access Management (RAM) user that has Tablestore access permissions.

Step 1: Configure the Tablestore resource in the EMQX console

  1. Go to the Data Integration page.

    1. Log on to the EMQX Platform console.

    2. Click your project.

    3. In the navigation pane on the left, click Data Integration.

  2. Create a connector.

    1. On the Data Integration page, in the Data Persistence section, click Alibaba Tablestore.

    2. On the New Connector page, configure the resource parameters as described in the following table.

      Parameter

      Required

      Example

      Description

      Connector Name

      Yes

      c-f0****

      Automatically generated by the system. This parameter cannot be modified.

      Remarks

      No

      Test Tablestore

      Remarks for the connector.

      Endpoint

      Yes

      https://myinstance.cn-hangzhou.vpc.tablestore.aliyuncs.com/

      The endpoint of Tablestore. If you use a VPC peering connection, use the VPC endpoint of Tablestore. If you connect over the public network, use the public endpoint of Tablestore.

      Instance Name

      Yes

      myinstance

      The name of the Tablestore instance.

      AccessKey ID

      Yes

      LTAI********************

      The AccessKey ID of your Alibaba Cloud account or RAM user.

      AccessKey Secret

      Yes

      ********************************

      The AccessKey secret of your Alibaba Cloud account or RAM user.

      Storage Model Type

      Yes

      Time Series

      The value is fixed to Time Series and cannot be modified.

      Enable TLS

      No

      Disabled

      TLS is disabled by default. To transfer data over the TLS protocol, turn on the Enable TLS switch and configure the TLS information.

      Advanced Settings

      No

      -

      In most cases, you can keep the default configurations. To change settings such as the connection pool size, startup timeout, or health check interval, click Advanced Settings and modify the configurations as needed.

    3. Click Test Connection to verify that the connection is working.

      Note

      If a connection test error occurs, verify that the database configuration is correct.

    4. After the test succeeds, click New.

    A dialog box appears, indicating that the connector has been created.

  3. Create a rule.

    After you create the resource, you can configure an associated rule to define how data is processed.

    1. In the Connector created successfully dialog box, click New Rule.

      Note

      On the Data Integration page, you can also click the fig_20220914_rule icon in the Actions column of the target connector to create a new rule.

    2. On the New Rule page, enter the SQL statement for the rule.

      The following sample SQL statement reads the client ID and payload from the temp_hum/emqx topic, and then reads the temperature and humidity values from the payload.

      SELECT
      
      payload.temp as temp, 
      payload.hum as hum,
      clientid
      
      FROM
      "temp_hum/emqx"

      You can enable the Enable Debug switch, modify the test data based on the fields in the SQL statement, and then click Test to view the results.

    3. Click Next.

  4. Create an output action.

    1. Configure the action parameters as described in the following table.

      image

      Parameter

      Required

      Example

      Description

      Use Connector

      Yes

      c-****

      Select the Tablestore sink connector that you created.

      Action Type

      Yes

      Alibaba Tablestore

      The value is fixed to Alibaba Tablestore and cannot be modified.

      Action Name

      Yes

      a-******

      The value is fixed to the name of the new action and cannot be modified.

      Remarks

      No

      Output action test

      Remarks for the action.

      Data Source

      No

      device_001

      The identifier of the data source that generates the timeline. This can be left empty.

      Table Name

      Yes

      temp_hum

      The name of the Tablestore time series table.

      Metric Name

      Yes

      cloud

      The metric name for the time series table. This is the name of the physical quantity or monitoring metric measured by the timeline data, such as temp or hum, to indicate that the timeline records temperature or humidity.

      Tags

      No

      Key: region

      Value: hangzhou

      Data tags. All data is processed as strings.

      Fields

      Yes

      Key: clientid

      Value: ${clientid}

      Key-value pairs for fields. The system automatically detects the data type of each field. Tablestore column values support multiple data types, including Boolean, integer, floating-point number, string, and binary. String data is processed as binary data by default to ensure optimal character set compatibility.

      In the Fields section, click Add and configure the field column, message value, and whether the value is an integer or binary.

      Timestamp

      No

      1663298365000000

      The time corresponding to the row of time series data. The format is a timestamp in microseconds (us).

      The default value is the timestamp in microseconds when the message arrives at EMQX.

      Important

      By default, MQTT messages in EMQX have a timestamp with millisecond precision, which cannot be used directly.

      Metadata Update Mode

      No

      MUM_NORMAL

      The update mode for time series metadata. Valid values are:

      • MUM_NORMAL (default): Normal mode.

      • MUM_IGNORE: Do not update metadata.

      Advanced Settings

      No

      -

      In most cases, you can keep the default configurations.

      To change settings such as the cache pool size, request timeout, health check interval, or maximum cache queue length, click Advanced Settings and modify the configurations as needed.

    2. Click Confirm.

      A Rule created successfully dialog box appears.

  5. Test the rule.

    After creating the rule, test it to ensure that it works correctly.

    1. In the Rule created successfully dialog box, click Go to Test Rule.

      Note

      You can also go to the Data Integration page, click the target rule name, and then on the Settings tab, enable the Enable Debug switch to test the rule.

    2. If debugging is not enabled, enable the Enable Debug switch.

    3. On the Test Rule tab, click Start Test.

    4. Click Input Simulated Data, and then configure the client ID, topic, and payload on the Simulated Data panel.

      image

    5. Click Submit Test.

      The test results are displayed on the Test Rule tab. You can view the data stored in Tablestore in the Tablestore console.

      image

Step 2: (Optional) Use the MQTT X tool to simulate reporting temperature and humidity data

Use the MQTT X tool to simulate sending temperature and humidity data to test the data storage.

  1. Create credentials.

    After you create the credentials, you can use them in the MQTT X tool to connect to the EMQX Platform.

    1. Log on to the EMQX Platform console.

    2. Click your project.

    3. In the navigation pane on the left, choose Access Control > Client Authentication.

    4. On the Default Authentication tab, click Add.

    5. In the Add Authentication dialog box, set the username and password, and then click Confirm.

  2. Obtain the endpoint and port of the EMQX cluster.

    Obtain the deployment endpoint to connect to the deployed EMQX cluster.

    1. Log on to the EMQX Platform console.

    2. Click your project.

    3. On the Overview page, obtain and record the Connection Address and connection port information.

  3. Use the MQTT X tool to simulate sending temperature and humidity data.

    1. Download and install the MQTT X tool.

    2. Open the MQTT X tool and click New Connection.

    3. Configure the basic connection parameters as described in the following table. You can keep the default values for other parameters.

      image

      Parameter

      Required

      Example

      Description

      Name

      Yes

      emqxtest

      A custom name for the connection from the MQTT X tool to EMQX Platform.

      Host

      Yes

      p*******.***.*********.aliyun.emqxcloud.cn

      The deployment endpoint of the EMQX cluster. Enter the Connection Address that you obtained from the EMQX Platform console.

      Port

      Yes

      1883

      The MQTT service port of the EMQX cluster. Enter the connection port that you obtained from the EMQX Platform console.

      Username

      Yes

      test

      The username and password used to connect to EMQX Cloud. Enter the username and password that you set when you created the credentials in the EMQX Platform console.

      Password

      Yes

      ********

    4. Click Connect.

  4. Send test data.

    1. Click New Subscription.

    2. In the New Subscription dialog box, configure the Topic and QoS, and then click Confirm.

      This example uses the topic temp_hum/emqx.

    3. Set the payload format to JSON, and configure the topic name and message body.

      The following is a JSON example:

      {
        "temp": "35.6",
        "hum": "99"
      }
    4. Click the fig_send icon to send the message.

Step 3: Verify the data in the Tablestore console

  1. Go to the Time Series Tables tab.

    1. Log on to the Tablestore console.

    2. In the top navigation bar, select a resource group and a region.

    3. On the Overview page, click the instance name.

    4. On the Instance Details tab, click Time Series Tables.

  2. On the Time Series Tables tab, click the name of the time series table and then click the Data Management tab. Alternatively, click Data Management in the Actions column.

  3. On the Data Management tab, enter cloud for the metric name, select 1 hour for the time range, and click Query.

    image