Message routing dynamically adjusts how data flows based on routing rules. Message routing allows you to route messages that meets the specified filtering conditions from the source to destination.

Prerequisites

An edge instance is created. You must configure message routing in an edge instance. The edge instance is assigned with a gateway, drivers, devices, and edge applications.

Procedure

  1. Log on to the IoT Platform console.
  2. In the left-side navigation pane, choose Link IoT Edge > Edge Instances.
  3. Find the edge instance for which you want to configure message routing, and click View.
  4. On the Instance Details page, click the Message Routing tab, and click Assign Route.Configure message routing
  5. In the dialog box that appears, specify the parameters as prompted. Then, click Confirm.
    Parameter Description
    Route Name The name of the message route. The name must be 4 to 32 characters in length.
    Message Source

    The source of messages. The valid values are described as follows:

    • Device: indicates that messages are sent from the devices assigned to the edge instance.
      • All Products: indicates that messages are sent from all the devices that are assigned to the edge instance.
      • All Devices: indicates that messages are sent from the devices of a specific product. The devices are assigned to the edge instance.
      • You can also specify the product and device name. In this scenario, messages are sent from the specified device.
    • Edge Applications: indicates that messages are sent from the edge application. You must select an edge application that is assigned to the edge instance.
    • IoT Hub: indicates that messages are sent from the cloud.
      If you select this option, the following custom topic category must be created for the gateway. We recommend that you check whether the topic category is created for the gateway. If the topic category is not created, create the topic category before proceeding. For more information, see Create a topic category.
      • The YourProductKey/${deviceName}/user/# custom topic category must be created. In this topic category, the YourProductKey variable indicates your product key, and the ${deviceName} element indicates your device name.
      • In the topic category settings, you must set the Device Operation Authorizations parameter to Subscribe.
    Message Topic Filter

    The message filtering condition. Only the messages that meet the specified filtering condition can be sent to the message destination. Specify this parameter as follows:

    • If you set Message Source to Device, select Property, Event, or All.
    • If you set Message Source to Edge Applications, create a custom topic category. For more information, see What is a topic. You can use wildcards such as the plus sign (+) and number sign (#) when you create a custom topic category.
    • If you set Message Source to IoT Hub, select a topic category from the drop-down list. Messages that belong to the topic category are sent to the message destination.
    Message Destination

    The destination of messages. The valid values are described as follows:

    • IoT Hub: indicates that the messages are sent to the cloud. If you select this option, you must specify the service level. For more information, see the Service Level parameter description.
    • Edge Applications: indicates that the messages are sent to the specified edge application. If you select this option, you must specify an edge application.
    Service Level

    The service level. This parameter is available only when you set Message Source to IoT Hub. This parameter specifies whether to resume data transmission from a breakpoint. The valid values are described as follows:

    • 0: indicates that data transmission is not resumed from a breakpoint. Messages fail to be sent to the cloud if network errors occur.
    • 1: indicates that data transmission is resumed from a breakpoint. If network errors occur, the messages that need to be sent to the cloud are stored in a local storage location. After network connections are reestablished, Link IoT Edge sends the historical data in the local storage location to the cloud.

      If you specify a message route that starts from an edge application and ends with IoT Hub, and you select 1 for this parameter, you must create the following custom topic category for the gateway. For more information, see Create a topic category. After the custom topic category is created, you must restart the gateway.

      • The /YourProductKey/YourDeviceName/user/restore custom topic category must be created. In this topic category, you must specify the YourProductKey and YourProductKey elements based on your device certificate.
      • In the topic category settings, you must set the Device Operation Authorizations parameter to Subscribe.
      You can send the historical data that failed to be sent to the cloud due to network errors by using this topic category. You can use the rule engine in the cloud to classify and process the historical data. The format of the historical data is described as follows:
      { "topic":"yyyyy", "payload":.... #string type or object type }

      In this format, the topic element indicates the original topic of the data that is to be sent to the cloud, and the payload element indicates the data that is to be sent to the cloud.

    Note If you select 1 for this parameter, data transmission can be resumed from a breakpoint. If network errors occur, the consumed CPU and disk I/O resources increase. All the available CPU and disk I/O resources may be consumed if you resume the transmission of large amounts of data. The upper limit for processing workloads varies based on the system performance. We recommend that you specify this parameter based on your business requirements.
    Note
    • If message routes have the same settings for the Message Source and Message Destination parameters but different settings for the Message Topic Filter parameter, each message is sent a maximum of one time. To be more specific, if a message has been sent by using one of the routes, the system stops matching other routes.
    • If message routes have different settings for the Message Source or Message Destination parameter, messages are sent by using all the message routes.

      Messages may be repeatedly sent. For example, you specify two message routes. For one of the message routes, the message source is all devices and message destination is IoT Hub. For the other message route, the message source is Device A and message destination is IoT Hub. If Device A sends a message to the cloud, the message is sent twice by using these two routes.