All Products
Search
Document Center

IoT Platform:Forward data to an AMQP consumer group

Last Updated:Jan 11, 2024

You can use the rules engine to forward messages from devices to IoT Platform. The messages are processed by using data parsing scripts, forwarded to AMQP consumer groups, and then consumed by AMQP clients.This article describes the data forwarding process. In this example, a Thing Specification Language (TSL) communication topic is used as the source topic.

Prerequisites

  • 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.

  • A destination AMQP consumer group is created. For more information, see Create a consumer group.

Create a data destination

  1. Log on to the IoT Platform console.
  2. 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.

  3. In the left-side navigation pane, choose Message Forwarding > Data Forwarding.
  4. In the upper-right corner of the Data Forwarding page, click Go to New Version 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 Message Forwarding > Data Forwarding.

  5. Click Data Destination. On the Data Destination 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.

    Select Operation

    Parameter

    Description

    Select Operation

    Select Publish to AMQP Subscribed Consumer Group.

    Consumer Group

    Select an existing consumer group as the data forwarding destination. Click Create Consumer Group to create a consumer group.

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 modify a script, see Script syntax.

    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. 
    writeAmqp(1000, data, "debug");
  6. Debugging

    The following figure shows the parameters.Debugging example

    The following result indicates that the script is implemented.

    Debugging 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.

Configure an AMQP client to consume messages

After the data is forwarded to the AMQP consumer group, your server consumes the messages by using the AMQP client. For more information about how to configure an AMQP client, see Connect an AMQP client to IoT Platform.

For sample code of the AMQP client implementation, see the following topics: