教程:第 2 部分 - 查看路由的消息Tutorial: Part 2 - View the routed messages

消息路由能够将遥测数据从 IoT 设备发送到内置的与事件中心兼容的终结点或自定义终结点,例如,Blob 存储、服务总线队列、服务总线主题和事件中心。Message routing enables sending telemetry data from your IoT devices to built-in Event Hub-compatible endpoints or custom endpoints such as blob storage, Service Bus Queues, Service Bus Topics, and Event Hubs. 若要配置自定义消息路由,请创建路由查询来自定义与特定条件匹配的路由。To configure custom message routing, you create routing queries to customize the route that matches a certain condition. 设置完成后,引入的数据将通过 IoT 中心自动路由到终结点。Once set up, the incoming data is automatically routed to the endpoints by the IoT Hub. 如果某个消息不匹配定义的任何路由查询,它将路由到默认终结点。If a message doesn't match any of the defined routing queries, it is routed to the default endpoint.

本教程包括 2 个部分,介绍如何通过 IoT 中心设置和使用这些自定义路由查询。In this 2-part tutorial, you learn how to set up and use these custom routing queries with IoT Hub. 将消息从 IoT 设备路由到多个终结点中的一个,包括 Blob 存储和服务总线队列。You route messages from an IoT device to one of multiple endpoints, including blob storage and a Service Bus queue. 路由到服务总线队列的消息将由逻辑应用拾取,并通过电子邮件发送。Messages to the Service Bus queue are picked up by a Logic App and sent via e-mail. 未定义自定义消息路由的消息将发送到默认终结点,然后由 Azure 流分析拾取,可在 Power BI 中直观查看。Messages that do not have custom message routing defined are sent to the default endpoint, then picked up by Azure Stream Analytics and viewed in a Power BI visualization.

若要完成本教程的第 1 和第 2 部分,请执行以下任务:To complete Parts 1 and 2 of this tutorial, you perform the following tasks:

第 I 部分:创建资源并设置消息路由Part I: Create resources, set up message routing

  • 创建资源 - IoT 中心、存储帐户、服务总线队列和模拟设备。Create the resources -- an IoT hub, a storage account, a Service Bus queue, and a simulated device. 使用 Azure 门户、Azure 资源管理器模板、Azure CLI 或 Azure PowerShell 即可完成此操作。This can be done using the Azure portal, an Azure Resource Manager template, the Azure CLI, or Azure PowerShell.
  • 在 IoT 中心为存储帐户和服务总线队列配置终结点和消息路由。Configure the endpoints and message routes in IoT Hub for the storage account and Service Bus queue.

第 II 部分:将消息发送到中心并查看路由的结果Part II: Send messages to the hub, view routed results

  • 创建一个逻辑应用,该应用将在消息添加到服务总线队列时触发,并发送电子邮件。Create a Logic App that is triggered and sends e-mail when a message is added to the Service Bus queue.
  • 下载并运行应用,该应用模拟 IoT 设备将消息发送到中心,以获得不同的路由选择。Download and run an app that simulates an IoT Device sending messages to the hub for the different routing options.
  • 为发送至默认终结点的数据创建 Power BI 可视化。Create a Power BI visualization for data sent to the default endpoint.
  • 查看结果...View the results ...
  • ...在服务总线队列和电子邮件中。...in the Service Bus queue and e-mails.
  • ...在存储帐户中。...in the storage account.
  • ...在 Power BI 可视化中。...in the Power BI visualization.

先决条件Prerequisites

  • 对于本教程的第 1 部分:For Part 1 of this tutorial:

    • 必须拥有 Azure 订阅。You must have an Azure subscription. 如果没有 Azure 订阅,可以在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.
  • 对于本教程的第 2 部分:For Part 2 of this tutorial:

    • 必须事先完成本教程的第 1 部分,并保留一些可用的资源。You must have completed Part 1 of this tutorial, and have the resources still available.
    • 安装 Visual StudioInstall Visual Studio.
    • 有权访问用于分析默认终结点的流分析的 Power BI 帐户。Have access to a Power BI account to analyze the default endpoint's stream analytics. 免费试用 Power BI。)(Try Power BI for free.)
    • 提供一个用于发送通知电子邮件的 Office 365 帐户。Have an Office 365 account for sending notification e-mails.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

消息路由规则Rules for routing the messages

下面是消息路由规则;这些规则是在本教程的第 1 部分设置的,本文(第二部分)将演示其工作方式。These are the rules for the message routing; these were set up in part 1 of this tutorial, and you see them work in this second part.

valuevalue 结果Result
级别=“storage”level="storage" 写入到 Azure 存储。Write to Azure Storage.
级别=“critical”level="critical" 写入服务总线队列。Write to a Service Bus queue. 逻辑应用从队列检索消息并使用 Office 365 通过电子邮件发送该消息。A Logic App retrieves the message from the queue and uses Office 365 to e-mail the message.
默认值default 使用 Power BI 显示此数据。Display this data using Power BI.

现在,创建要将消息路由到的资源,运行某个应用以将消息发送到中心,然后查看路由的运作方式。Now you create the resources to which the messages will be routed, run an app to send messages to the hub, and see the routing in action.

创建逻辑应用Create a Logic App

服务总线队列将用于检索指定为关键的消息。The Service Bus queue is to be used for receiving messages designated as critical. 设置一个逻辑应用,用于监视服务总线队列,并在消息添加到队列时发送电子邮件。Set up a Logic app to monitor the Service Bus queue, and send an e-mail when a message is added to the queue.

  1. Azure 门户中,选择“+ 创建资源”。 In the Azure portal, select + Create a resource. 在搜索框中输入“逻辑应用”,并单击 Enter 。Put logic app in the search box and click Enter. 在显示的搜索结果中选择“逻辑应用”,然后选择“创建”进入“创建逻辑应用”窗格 。From the search results displayed, select Logic App, then select Create to continue to the Create logic app pane. 填充字段。Fill in the fields.

    名称:此字段是逻辑应用的名称。Name: This field is the name of the logic app. 本教程使用 ContosoLogicApp 。This tutorial uses ContosoLogicApp.

    订阅:选择 Azure 订阅。Subscription: Select your Azure subscription.

    资源组:选择“使用现有项”并选择你的资源组 。Resource group: Select Use existing and select your resource group. 本教程使用 ContosoResources 。This tutorial uses ContosoResources.

    位置:使用你的位置。Location: Use your location.

    Log Analytics:应关闭此开关。Log Analytics: This toggle should be turned off.

    “创建逻辑应用”屏幕

    选择“创建” 。Select Create. 可能需要花费几分钟时间才能部署应用。It may take a few minutes for the app to deploy.

  2. 现在转到该逻辑应用。Now go to the Logic App. 转到“逻辑应用”的最简单方法是选择“资源组”,选择你的资源组(本教程使用 ContosoResources),然后从资源列表中选择“逻辑应用” 。The easiest way to get to the Logic App is to select Resource groups, select your resource group (this tutorial uses ContosoResources), then select the Logic App from the list of resources.

    随即将显示该逻辑应用设计器页面(可能需要向右滚动才可查看完整页面)。The Logic Apps Designer page appears (you might have to scroll over to the right to see the full page). 在“逻辑应用设计器”页上向下滚动,直到出现带有“空白逻辑应用 +”字样的磁贴;选择该磁贴 。On the Logic Apps Designer page, scroll down until you see the tile that says Blank Logic App + and select it. 默认选项卡是“为你提供”。The default tab is "For You". 如果此窗格为空,请选择“全部”以查看所有可用的连接器和触发器。 If this pane is blank, select All to see all of the connectors and triggers available.

  3. 从连接器列表中选择“服务总线”。 Select Service Bus from the list of connectors.

    连接器列表

  4. 此时会显示触发器的列表。A list of triggers is displayed. 选择“在队列中收到消息时(自动完成)/服务总线” 。Select When a message is received in a queue (auto-complete) / Service Bus.

    服务总线的触发器列表

  5. 在下一屏幕上,填写“连接名称”。On the next screen, fill in the Connection Name. 本教程使用 ContosoConnection 。This tutorial uses ContosoConnection.

    为服务总线队列设置连接

    选择“服务总线”命名空间。Select the Service Bus namespace. 本教程使用 ContosoSBNamespace 。This tutorial uses ContosoSBNamespace. 选择该命名空间时,门户会查询该“服务总线”命名空间以检索密钥。When you select the namespace, the portal queries the Service Bus namespace to retrieve the keys. 依次选择“RootManageSharedAccessKey”、“创建” 。Select RootManageSharedAccessKey and select Create.

    完成设置连接

  6. 在下一步屏幕上,从下拉列表选择队列名称(本教程使用 contososbqueue) 。On the next screen, select the name of the queue (this tutorial uses contososbqueue) from the dropdown list. 其余字段可使用默认值。You can use the defaults for the rest of the fields.

    队列选项

  7. 现在,设置一个在队列接收到消息时发送电子邮件的操作。Now set up the action to send an e-mail when a message is received in the queue. 在逻辑应用设计器中选择“+ 新建步骤”以添加步骤,然后选择“全部”以查看所有可用选项。 In the Logic Apps Designer, select + New step to add a step, then select All to see all of the options available. 在“选择操作”窗格中,找到并选择“Office 365 Outlook” 。In the Choose an action pane, find and select Office 365 Outlook. 在“操作”屏幕上,选择“发送电子邮件/Office 365 Outlook” 。On the Actions screen, select Send an e-mail / Office 365 Outlook.

    Office365 选项

  8. 登录到 Office 365 帐户并设置连接。Sign in to your Office 365 account to set up the connection. 如果此操作超时,只需重试即可。If this times out, just try again. 为电子邮件收件人指定电子邮件地址。Specify the e-mail addresses for the recipient(s) of the e-mails. 同时指定主题,并在正文键入想要让收件人看到的消息。Also specify the subject, and type what message you'd like the recipient to see in the body. 测试时,可填入自己的电子邮件地址作为收件人。For testing, fill in your own e-mail address as the recipient.

    选择“添加动态内容”,以显示消息中可包含的内容 。Select Add dynamic content to show the content from the message that you can include. 选择“内容”- 将包含电子邮件中的消息 。Select Content -- it will include the message in the e-mail.

    逻辑应用的电子邮件选项

  9. 选择“保存” 。Select Save. 然后关闭逻辑应用设计器。Then close the Logic App Designer.

设置 Azure 流分析Set up Azure Stream Analytics

若要在 Power BI 可视化中查看数据,首先需要设置流分析作业来检索数据。To see the data in a Power BI visualization, first set up a Stream Analytics job to retrieve the data. 请记住,只会将“级别”为“常规”的消息发送到默认终结点,并由针对 Power BI 可视化的流分析作业检索 。Remember that only the messages where the level is normal are sent to the default endpoint, and will be retrieved by the Stream Analytics job for the Power BI visualization.

创建流分析作业Create the Stream Analytics job

  1. Azure 门户中,选择“创建资源” > “物联网” > “流分析作业”。 In the Azure portal, select Create a resource > Internet of Things > Stream Analytics job.

  2. 为作业输入以下信息。Enter the following information for the job.

    作业名称:作业的名称。Job name: The name of the job. 该名称必须全局唯一。The name must be globally unique. 本教程使用 contosoJob 。This tutorial uses contosoJob.

    订阅:本教程使用的 Azure 订阅。Subscription: The Azure subscription you are using for the tutorial.

    资源组:使用 IoT 中心所用的同一资源组。Resource group: Use the same resource group used by your IoT hub. 本教程使用 ContosoResources 。This tutorial uses ContosoResources.

    位置:使用设置脚本中所用的同一位置。Location: Use the same location used in the setup script.

    创建流分析作业

  3. 选择“创建” 来创建作业。Select Create to create the job. 部署可能需要几分钟时间。It may take a few minutes to deploy.

    若要返回到该作业,请选择“资源组”。 To get back to the job, select Resource groups. 本教程使用 ContosoResources 。This tutorial uses ContosoResources. 选择资源组,然后在资源列表中选择流分析作业。Select the resource group, then select the Stream Analytics job in the list of resources.

向流分析作业添加输入Add an input to the Stream Analytics job

  1. 在“作业拓扑”下选择“输入”。 Under Job Topology, select Inputs.

  2. 在“输入”窗格中,依次选择“添加流输入”、“IoT 中心” 。In the Inputs pane, select Add stream input and select IoT Hub. 在出现的屏幕上,填写以下字段:On the screen that comes up, fill in the following fields:

    输入别名:本教程使用 contosoinputs 。Input alias: This tutorial uses contosoinputs.

    从订阅选择 IoT 中心:选中此单选按钮选项。Select IoT Hub from your subscription: Select this radio button option.

    订阅:选择本教程使用的 Azure 订阅。Subscription: Select the Azure subscription you're using for this tutorial.

    IoT 中心:选择 IoT 中心。IoT Hub: Select the IoT Hub. 本教程使用 ContosoTestHub 。This tutorial uses ContosoTestHub.

    终结点:选择“消息传送” 。Endpoint: Select Messaging. (如果选择操作监视,将获得有关 IoT 中心的遥测数据,而不是正在发送的数据。)(If you select Operations Monitoring, you get the telemetry data about the IoT hub rather than the data you're sending through.)

    共享访问策略名称:选择“服务” 。Shared access policy name: Select service. 门户将填充共享访问策略密钥。The portal fills in the Shared Access Policy Key for you.

    使用者组:选择在本教程的第 1 部分中设置的使用者组。Consumer group: Select the consumer group set up in Part 1 of this tutorial. 本教程使用 contosoconsumers 。This tutorial uses contosoconsumers.

    其余字段接受默认值。For the rest of the fields, accept the defaults.

    设置流分析作业的输入

  3. 选择“保存” 。Select Save.

向流分析作业添加输出Add an output to the Stream Analytics job

  1. 在“作业拓扑”下选择“输出”。 Under Job Topology, select Outputs.

  2. 在“输出”窗格中,依次选择“添加”、“Power BI” 。In the Outputs pane, select Add, and then select Power BI. 在出现的屏幕上,填写以下字段:On the screen that comes up, fill in the following fields:

    输出别名:输出的唯一别名。Output alias: The unique alias for the output. 本教程使用 contosooutputs 。This tutorial uses contosooutputs.

    数据集名称:要在 Power BI 中使用的数据集的名称。Dataset name: Name of the dataset to be used in Power BI. 本教程使用 contosodataset 。This tutorial uses contosodataset.

    表名称:要在 Power BI 中使用的表的名称。Table name: Name of the table to be used in Power BI. 本教程使用 contosotable 。This tutorial uses contosotable.

    在剩余字段中使用默认值。Accept the defaults for the rest of the fields.

  3. 选择“授权”并登录到 Power BI 帐户 。Select Authorize, and sign in to your Power BI account. (这可能需要多次重试。)(This may take more than one try).

    设置流分析作业的输出

  4. 选择“保存” 。Select Save.

配置流分析作业的查询Configure the query of the Stream Analytics job

  1. 在“作业拓扑”下选择“查询”。 Under Job Topology, select Query.

  2. [YourInputAlias] 替换为作业的输入别名。Replace [YourInputAlias] with the input alias of the job. 本教程使用 contosoinputs 。This tutorial uses contosoinputs.

  3. [YourOutputAlias] 替换为作业的输出别名。Replace [YourOutputAlias] with the output alias of the job. 本教程使用 contosooutputs 。This tutorial uses contosooutputs.

    设置流分析作业的查询

  4. 选择“保存” 。Select Save.

  5. 关闭“查询”窗格。Close the Query pane. 随后将返回到资源组中资源的视图。You return to the view of the resources in the Resource Group. 选择流分析作业。Select the Stream Analytics job. 本教程中将其称为 contosoJobThis tutorial calls it contosoJob.

运行流分析作业Run the Stream Analytics job

在流分析作业中,单击“启动” > “立即” > “启动”。In the Stream Analytics job, select Start > Now > Start. 成功启动作业以后,作业状态将从“已停止” 更改为“正在运行” 。Once the job successfully starts, the job status changes from Stopped to Running.

设置 Power BI 报表需要数据,因此将先创建设备并运行设备模拟应用程序再设置 Power BI。To set up the Power BI report, you need data, so you'll set up Power BI after creating the device and running the device simulation application.

运行模拟设备应用Run simulated device app

在本教程的第 1 部分中,我们已设置一个使用 IoT 设备进行模拟的设备。In Part 1 of this tutorial, you set up a device to simulate using an IoT device. 在本部分中,我们将下载 .NET 控制台应用,用于模拟设备向 IoT 中心发送设备到云的消息(假设在第 1 部分中尚未下载相应的应用和资源)。In this section, you download the .NET console app that simulates that device sending device-to-cloud messages to an IoT hub (assuming you didn't already download the app and resources in Part 1).

此应用程序针对每个不同的消息路由方法发送消息。This application sends messages for each of the different message routing methods. 下载内容还带有一个文件夹,其中包含完整的 Azure 资源管理器模板和参数文件,以及 Azure CLI 和 PowerShell 脚本。There is also a folder in the download that contains the complete Azure Resource Manager template and parameters file, as well as the Azure CLI and PowerShell scripts.

如果在本教程的第 1 部分中未从存储库下载这些文件,现在请继续从 IoT 设备模拟下载。If you didn't download the files from the repository in Part 1 of this tutorial, go ahead and download them now from IoT Device Simulation. 选择此链接可下载包含多个应用程序的存储库;要查找的解决方案是 iot-hub/Tutorials/Routing/IoT_SimulatedDevice.sln。Selecting this link downloads a repository with several applications in it; the solution you are looking for is iot-hub/Tutorials/Routing/IoT_SimulatedDevice.sln.

双击解决方案文件 (IoT_SimulatedDevice.sln) 以在 Visual Studio 中打开代码,然后打开 Program.cs。Double-click on the solution file (IoT_SimulatedDevice.sln) to open the code in Visual Studio, then open Program.cs. 使用 IoT 中心主机名代替 {your hub name}Substitute {your hub name} with the IoT hub host name. IoT 中心主机名的格式为“{iot-hub-name}.azure-devices.cn” 。The format of the IoT hub host name is {iot-hub-name}.azure-devices.cn. 本教程的中心主机名为“ContosoTestHub.azure-devices.cn” 。For this tutorial, the hub host name is ContosoTestHub.azure-devices.cn. 接下来,使用之前设置模拟设备时保存的设备密钥代替 {your device key}Next, substitute {your device key} with the device key you saved earlier when setting up the simulated device.

     static string s_myDeviceId = "Contoso-Test-Device";
     static string s_iotHubUri = "ContosoTestHub.azure-devices.cn";
     // This is the primary key for the device. This is in the portal. 
     // Find your IoT hub in the portal > IoT devices > select your device > copy the key. 
     static string s_deviceKey = "{your device key}";

运行和测试Run and test

运行控制台应用程序。Run the console application. 稍等几分钟。Wait a few minutes. 可在应用程序的控制台屏幕上看到正在发送的消息。You can see the messages being sent on the console screen of the application.

此应用每隔一秒发送一条新的设备到云消息到 IoT 中心。The app sends a new device-to-cloud message to the IoT hub every second. 此消息包含一个 JSON 序列化对象,其中具有设备 ID、温度、湿度和消息级别(级别默认为 normal)。The message contains a JSON-serialized object with the device ID, temperature, humidity, and message level, which defaults to normal. 它随机分配 critical 级别或 storage 级别,使消息路由到存储帐户或路由到服务总线队列(这会触发逻辑应用发送电子邮件)。It randomly assigns a level of critical or storage, causing the message to be routed to the storage account or to the Service Bus queue (which triggers your Logic App to send an e-mail). 默认 (normal) 读取内容将在之后设置的 BI 报表中显示。The default (normal) readings will be displayed in the BI report you set up next.

如果所有内容都正确设置,则此时应可以看见以下结果:If everything is set up correctly, at this point you should see the following results:

  1. 开始收到关键消息相关的电子邮件。You start getting e-mails about critical messages.

    生成的电子邮件

    此结果表示以下语句为 true。This result means the following statements are true.

    • 到服务总线队列的路由运行正常。The routing to the Service Bus queue is working correctly.
    • 从服务总线队列检索消息的逻辑应用运行正常。The Logic App retrieving the message from the Service Bus queue is working correctly.
    • 连接到 Outlook 的逻辑应用连接器工作正常。The Logic App connector to Outlook is working correctly.
  2. Azure 门户中选择“资源组”,然后选择你的资源组 。In the Azure portal, select Resource groups and select your Resource Group. 本教程使用 ContosoResources 。This tutorial uses ContosoResources.

    依次选择存储帐户、“容器” 和相应的容器。Select the storage account, select Containers, then select the Container. 本教程使用 contosoresults 。This tutorial uses contosoresults. 现在应该可以看见一个文件夹,可继续深入查看目录,直到看见一个或多个文件。You should see a folder, and you can drill down through the directories until you see one or more files. 打开其中某个文件;这些文件中包含路由到存储帐户的条目。Open one of those files; they contain the entries routed to the storage account.

    存储中的结果文件

此结果表示以下语句为 true。This result means the following statement is true.

  • 到存储帐户的路由运行正常。The routing to the storage account is working correctly.

现在,在应用程序仍在运行的情况下,设置 Power BI 可视化以显示来自默认路由的消息。Now with the application still running, set up the Power BI visualization to see the messages coming through the default routing.

设置 Power BI 可视化效果Set up the Power BI visualizations

  1. 登录到 Power BI 帐户。Sign in to your Power BI account.

  2. 转到“工作区”,然后选择为流分析作业创建输出时设置的工作区 。Go to Workspaces and select the workspace that you set when you created the output for the Stream Analytics job. 本教程使用“我的工作区” 。This tutorial uses My Workspace.

  3. 选择“数据集”。 Select Datasets. 如果没有任何数据集,请在几分钟后再次检查。If you don't have any datasets, wait a few minutes and check again.

    此时会看到列出的数据集,该数据集是在为流分析作业创建输出时指定的。You should see the listed dataset that you specified when you created the output for the Stream Analytics job. 本教程使用 contosodataset 。This tutorial uses contosodataset. (数据集首次显示的过程可能需要 5-10 分钟。)(It may take 5-10 minutes for the dataset to show up the first time.)

  4. 在“操作”下,选择第一个图标以创建报表。 Under ACTIONS, select the first icon to create a report.

    Power BI 工作区,其中突出显示了“操作”和报表图标

  5. 创建折线图,显示某段时间的实时温度。Create a line chart to show real-time temperature over time.

    • 在报表创建页上,选择折线图图标以添加折线图。On the report creation page, add a line chart by selecting the line chart icon.

      可视化效果和字段

    • 在“字段”窗格中展开一个表,该表是在为流分析作业创建输出时指定的。 On the Fields pane, expand the table that you specified when you created the output for the Stream Analytics job. 本教程使用 contosotable 。This tutorial uses contosotable.

    • EventEnqueuedUtcTime 拖至“可视化效果”窗格中的“轴”。 Drag EventEnqueuedUtcTime to Axis on the Visualizations pane.

    • 将“温度”拖至“值”。 Drag temperature to Values.

    已创建一个折线图。A line chart is created. X 轴显示 UTC 时区的日期和时间。The x-axis displays date and time in the UTC time zone. Y 轴显示来自传感器的温度。The y-axis displays temperature from the sensor.

  6. 创建另一个折线图,显示某段时间的实时湿度。Create another line chart to show real-time humidity over time. 若要设置第二个图表,请对第一个图表执行相同的过程,将 EventEnqueuedUtcTime 置于 x 轴(),将“湿度” 置于 y 轴()。To set up the second chart, follow the same process for the first chart, placing EventEnqueuedUtcTime on the x-axis (Axis) and humidity on the y-axis (Values).

    最终的 Power BI 报表,其中包含两个图表

  7. 选择“保存” 以保存报表,并在出现提示时输入报表名称。Select Save to save the report, entering a name for the report if prompted.

现在应在两个图表上都能看到数据。You should be able to see data on both charts. 此结果表示以下语句为 true:This result means the following statements are true:

  • 到默认终结点的路由运行正常。The routing to the default endpoint is working correctly.
  • Azure 流分析作业的流式传输正常。The Azure Stream Analytics job is streaming correctly.
  • Power BI 可视化设置正确。The Power BI Visualization is set up correctly.

选择 Power BI 窗口顶部的“刷新”按钮可刷新图表,以查看最近的数据。You can refresh the charts to see the most recent data by selecting the Refresh button on the top of the Power BI window.

清理资源Clean up resources

若要删除在本教程的两个部分中创建的所有 Azure 资源,请删除资源组。If you want to remove all of the Azure resources you've created through both parts of this tutorial, delete the resource group. 此操作会一并删除组中包含的所有资源。This action deletes all resources contained within the group. 在这种情况下,它会删除 IoT 中心、服务总线命名空间和队列、逻辑应用、存储帐户和资源组本身。In this case, it removes the IoT hub, the Service Bus namespace and queue, the Logic App, the storage account, and the resource group itself. 还可以删除 Power BI 资源并清除在教程中发送的电子邮件。You can also remove the Power BI resources and clear the emails sent during the tutorial.

清理 Power BI 可视化效果中的资源Clean up resources in the Power BI visualization

登录到 Power BI 帐户。Sign in to your Power BI account. 转到你的工作区。Go to your workspace. 本教程使用“我的工作区” 。This tutorial uses My Workspace. 若要删除 Power BI 可视化效果,请转到“数据集”并选择垃圾桶图标来删除相应的数据集。To remove the Power BI visualization, go to DataSets and select the trash can icon to delete the dataset. 本教程使用 contosodataset 。This tutorial uses contosodataset. 删除数据集时,报表也随之删除。When you remove the dataset, the report is removed as well.

使用 Azure CLI 清理资源Use the Azure CLI to clean up resources

若要删除资源组,请使用 az group delete 命令。To remove the resource group, use the az group delete command. 在本教程的开头,$resourceGroup 已设置为 ContosoResources$resourceGroup was set to ContosoResources back at the beginning of this tutorial.

az group delete --name $resourceGroup

使用 PowerShell 清理资源Use PowerShell to clean up resources

若要删除资源组,请使用 Remove-AzResourceGroup 命令。To remove the resource group, use the Remove-AzResourceGroup command. 在本教程的开头,$resourceGroup 已设置为 ContosoResources$resourceGroup was set to ContosoResources back at the beginning of this tutorial.

Remove-AzResourceGroup -Name $resourceGroup

清理测试电子邮件Clean up test emails

你可能还希望删除收件箱中在设备应用程序运行时通过逻辑应用生成的电子邮件数。You may also want to delete the quantity of emails in your inbox that were generated through the Logic App while the device application was running.

后续步骤Next steps

本教程的第 2 部分(即本文)已介绍如何通过执行以下任务,使用消息路由将 IoT 中心消息路由到不同的目标。In this 2-part tutorial, you learned how to use message routing to route IoT Hub messages to different destinations by performing the following tasks.

第 I 部分:创建资源并设置消息路由Part I: Create resources, set up message routing

  • 创建资源 - IoT 中心、存储帐户、服务总线队列和模拟设备。Create the resources -- an IoT hub, a storage account, a Service Bus queue, and a simulated device.
  • 在 IoT 中心为存储帐户和服务总线队列配置终结点和消息路由。Configure the endpoints and message routes in IoT Hub for the storage account and Service Bus queue.

第 II 部分:将消息发送到中心并查看路由的结果Part II: Send messages to the hub, view routed results

  • 创建一个逻辑应用,该应用将在消息添加到服务总线队列时触发,并发送电子邮件。Create a Logic App that is triggered and sends e-mail when a message is added to the Service Bus queue.
  • 下载并运行应用,该应用模拟 IoT 设备将消息发送到中心,以获得不同的路由选择。Download and run an app that simulates an IoT Device sending messages to the hub for the different routing options.
  • 为发送至默认终结点的数据创建 Power BI 可视化。Create a Power BI visualization for data sent to the default endpoint.
  • 查看结果...View the results ...
  • ...在服务总线队列和电子邮件中。...in the Service Bus queue and e-mails.
  • ...在存储帐户中。...in the storage account.
  • ...在 Power BI 可视化中。...in the Power BI visualization.

转到下一教程,了解如何管理 IoT 设备的状态。Advance to the next tutorial to learn how to manage the state of an IoT device.