Set up message routing
Message routing uses routing rules to dynamically determine the path for messages. Based on filter conditions, messages are routed from a source node to a destination node.
Prerequisites
You have created an edge instance and assigned a gateway, drivers, devices, and edge applications to it.Procedure
- Log on to the IoT Edge console.
- In the navigation pane on the left, click Edge Instances.
- Find the instance for which you want to set up message routing and click View in the Actions column.
- On the Instance Details page, click the Message Routing tab and then click Assign Route.

- In the Assign Message Route dialog box, set the configuration items and click OK.
Parameter Description Route Name Set a name for the message route. The name must be 4 to 32 characters in length. Chinese characters and symbols are counted as two characters. Message Source Select the sender of the message.
- Device: The message is sent by a device that is assigned to the instance.
You must specify the product or device for the message source. For more information, see the descriptions of the Product and Device parameters in this table.
- Edge Application: The message is sent from an edge application. Select the name of an application that is assigned to the edge instance.Note Only edge applications of the Function Compute type support message routing.
- IoT Hub: The message is sent from the cloud. This option depends on the following custom topic category under the gateway product. Confirm that this topic category exists for your gateway product. If not, add the topic category. For more information about how to add the topic category, see Use custom topics for communication.
- Topic category:
/YourProductKey/${deviceName}/user/#. YourProductKey is a variable that represents the ProductKey of the gateway product. ${deviceName} is a wildcard for the DeviceName. - Device permission: Subscribe.
- Topic category:
- Stream Analytics: The message is sent from Stream Analytics. Select the name of a Stream Analytics task that is assigned to the instance.
Product If you set Message Source to Device, select a product for the message source. - All Products: All devices under the edge instance are message sources.
- Select multiple products: All devices that belong to these products and are assigned to the edge instance are message sources. Note You can select up to 100 products for a message route.
- Select a single product: Devices that belong to this product and are assigned to the edge instance are used as message sources. You must then specify the devices. For more information, see the description of the Device parameter in this table.
Device If you set Message Source to Device and select only one product for the Product parameter, select specific devices under that product as the message source. - All Devices: All devices that belong to the product and are assigned to the edge instance are message sources.
- Select multiple devices: The selected devices are used as message sources. Note You can select up to 100 devices for a message route.
- Select a single device: The specified device is used as the message source.
Message Topic Filter Set the filter condition for messages. Only messages that meet this condition can reach the destination. Set the filter as follows:
- If the message source is a device, you can select Property, Event, or All.
- If the message source is an edge application or stream data analytics, you must define a custom topic (for more information, see What is a Topic?). You can use the wildcard characters
+and#. - If the message source is IoT Hub, select a topic category to filter from the drop-down list.
Message Destination The receiver of the message.
- IoT Hub: The message is uploaded to the cloud. You must set the service level. For more information, see the description of the Service Level parameter in this table.
- Edge Application: Specify the name of an application that is assigned to the edge instance.Note Only edge applications of the Function Compute type support message routing.
- Stream Analytics: This option is available only when the message source is Device. Specify the name of the Stream Analytics task.
Service Level If the message destination is IoT Hub, set the service level to determine whether your device data can be retransmitted after a network disconnection.
- 0: Messages that need to be uploaded to the cloud are lost if the network is disconnected.
- 1: If the network is disconnected, messages that need to be uploaded to the cloud are saved to local storage. After the network recovers, IoT Edge retransmits the historical data from local storage to the cloud.
If the message route is from an edge application to IoT Hub and you set the service level to 1, you must define the following custom topic category for the gateway product and then restart the gateway. For more information about how to add the topic category, see Use custom topics for communication.
- Topic category:
/YourProductKey/YourDeviceName/user/restore. Replace YourProductKey and YourDeviceName with the device certificate information of the gateway. - Device permission: Subscribe.
Historical data that is retransmitted after a network disconnection is uploaded to the cloud through this topic. You can use the rules engine in the cloud to categorize and process the retransmitted historical data. The historical data is in the following format:{ "topic":"yyyyy", "payload":.... #string or object }topicis the topic of the original data that was uploaded to the cloud.payloadis the content of the original data. - Topic category:
Note If you set the service level to 1, CPU and disk I/O usage increases during a network disconnection. A large volume of data might exhaust system disk and CPU resources. The maximum load that a system can handle varies based on its performance. Choose whether to enable data retransmission based on your requirements.Note- For routes with the same Message Source and Message Destination but different Message Topic Filters, a message is forwarded only by the first matching route. No other routes are matched or executed.
- Message SourceMessage DestinationRoutes that have a different or are matched and executed independently.
This can cause a message to be forwarded multiple times. For example, one routing rule has Message Source set to all devices and Message Destination set to IoT Hub. Another routing rule has Message Source set to Device A and Message Destination also set to IoT Hub. When Device A sends a message, both routing rules are matched and executed, sending the message from Device A to IoT Hub twice.
- Device: The message is sent by a device that is assigned to the instance.