快速入门:使用 Azure 门户创建流分析作业Quickstart: Create a Stream Analytics job by using the Azure portal

本快速入门介绍如何开始创建流分析作业。This quickstart shows you how to get started with creating a Stream Analytics job. 在本快速入门中,请定义一个流分析作业,以便读取实时流数据并筛选温度高于 27 的消息。In this quickstart, you define a Stream Analytics job that reads real-time streaming data and filters messages with a temperature greater than 27. 流分析作业会从 IoT 中心读取数据,对数据进行转换,然后将数据写回到 Blob 存储中的容器。Your Stream Analytics job will read data from IoT Hub, transform the data, and write the data back to a container in blob storage. 在本快速入门中使用的输入数据由 Raspberry Pi 联机模拟器生成。The input data used in this quickstart is generated by a Raspberry Pi online simulator.

开始之前Before you begin

对输入数据进行准备Prepare the input data

在定义流分析作业之前,应该准备输入数据。Before defining the Stream Analytics job, you should prepare the input data. 实时传感器数据将引入到 IoT 中心,随后配置为作业输入。The real-time sensor data is ingested to IoT Hub, which later configured as the job input. 若要对作业所需的输入数据进行准备,请完成以下步骤:To prepare the input data required by the job, complete the following steps:

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 选择“创建资源” > “物联网” > “IoT 中心”。Select Create a resource > Internet of Things > IoT Hub.

  3. 在“IoT 中心”窗格中,输入以下信息: In the IoT Hub pane, enter the following information:

    设置Setting 建议的值Suggested value 说明Description
    订阅Subscription <Your subscription> 选择要使用的 Azure 订阅。Select the Azure subscription that you want to use.
    资源组Resource group asaquickstart-resourcegroupasaquickstart-resourcegroup 选择“新建”****,然后输入帐户的新资源组名称。Select Create New and enter a new resource-group name for your account.
    区域Region <Select the region that is closest to your users> 选择可以在其中托管 IoT 中心的地理位置。Select a geographic location where you can host your IoT Hub. 使用最靠近用户的位置。Use the location that's closest to your users.
    IoT 中心名称IoT Hub Name MyASAIoTHubMyASAIoTHub 选择 IoT 中心的名称。Select a name for your IoT Hub.

    创建 IoT 中心

  4. 在完成时选择“下一步:**** 设置大小和规模”。Select Next: Set size and scale.

  5. 选择“定价和缩放层”****。Choose your Pricing and scale tier. 就本快速入门来说,请选择“F1 - 免费”层(前提是此层在订阅上仍然可用)****。For this quickstart, select the F1 - Free tier if it's still available on your subscription. 有关详细信息,请参阅 IoT 中心定价For more information, see IoT Hub pricing.

    设置 IoT 中心的大小和规模

  6. 选择“查看 + 创建”。Select Review + create. 查看 IoT 中心信息,然后单击“创建”****。Review your IoT Hub information and click Create. 创建 IoT 中心可能需要数分钟的时间。Your IoT Hub might take a few minutes to create. 可在“通知”窗格中监视进度。****You can monitor the progress in the Notifications pane.

  7. 在 IoT 中心导航菜单的“IoT 设备”下单击“添加”**** ****。In your IoT Hub navigation menu, click Add under IoT devices. 添加“设备 ID”,然后单击“保存”。**** ****Add a Device ID and click Save.

    将设备添加到 IoT 中心

  8. 创建设备后,请从“IoT 设备”列表打开设备****。Once the device is created, open the device from the IoT devices list. 复制“连接字符串 -- 主密钥”并将其保存到记事本,供稍后使用****。Copy the Connection string -- primary key and save it to a notepad to use later.

    复制 IoT 中心设备连接字符串

创建 Blob 存储Create blob storage

  1. 从 Azure 门户的左上角选择“创建资源” > “存储” > “存储帐户”。From the upper left-hand corner of the Azure portal, select Create a resource > Storage > Storage account.

  2. 在“创建存储帐户”**** 窗格中,输入存储帐户名称、位置和资源组。In the Create storage account pane, enter a storage account name, location, and resource group. 选择与创建的 IoT 中心相同的位置和资源组。Choose the same location and resource group as the IoT Hub you created. 然后单击“查看 + 创建”,以便创建帐户****。Then click Review + create to create the account.

    创建存储帐户

  3. 创建存储帐户以后,请在“概览”窗格上选择“Blob”磁贴。**** ****Once your storage account is created, select the Blobs tile on the Overview pane.

    存储帐户概述

  4. 从“Blob 服务”**** 页面中,选择“容器”****,为你的容器提供一个名称,例如 container1From the Blob Service page, select Container and provide a name for your container, such as container1. 将“公共访问级别”保留为“专用(非匿名访问)”,然后选择“确定”。**** **** ****Leave the Public access level as Private (no anonymous access) and select OK.

    创建 blob 容器

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

  1. 登录到 Azure 门户。Sign in to the Azure portal.

  2. 在 Azure 门户的左上角选择“创建资源”。Select Create a resource in the upper left-hand corner of the Azure portal.

  3. 从结果列表中选择“分析” > “流分析作业”。Select Analytics > Stream Analytics job from the results list.

  4. 使用以下信息填写“流分析作业”页:Fill out the Stream Analytics job page with the following information:

    设置Setting 建议的值Suggested value 说明Description
    作业名称Job name MyASAJobMyASAJob 输入用于标识流分析作业的名称。Enter a name to identify your Stream Analytics job. 流分析作业名称只能包含字母数字字符、连字符和下划线,其长度必须介于 3 到 63 个字符之间。Stream Analytics job name can contain alphanumeric characters, hyphens, and underscores only and it must be between 3 and 63 characters long.
    订阅Subscription <Your subscription> 选择要用于此作业的 Azure 订阅。Select the Azure subscription that you want to use for this job.
    资源组Resource group asaquickstart-resourcegroupasaquickstart-resourcegroup 选择与 IoT 中心相同的资源组。Select the same resource group as your IoT Hub.
    位置Location <Select the region that is closest to your users> 选择可以在其中托管流分析作业的地理位置。Select geographic location where you can host your Stream Analytics job. 使用最靠近用户的位置,以便改进性能并减少数据传输成本。Use the location that's closest to your users for better performance and to reduce the data transfer cost.
    流式处理单位Streaming units 11 流单元表示执行作业所需的计算资源。Streaming units represent the computing resources that are required to execute a job. 默认情况下,此值设置为 1。By default, this value is set to 1. 若要了解如何缩放流单元,请参阅了解和调整流单元一文。To learn about scaling streaming units, refer to understanding and adjusting streaming units article.
    宿主环境Hosting environment Cloud 流分析作业可以部署到云或边缘设备。Stream Analytics jobs can be deployed to cloud or edge. 可以通过云部署到 Azure 云,通过“Edge”部署到 IoT Edge 设备。Cloud allows you to deploy to Azure Cloud, and Edge allows you to deploy to an IoT Edge device.

    创建作业

  5. 选中用于将作业置于仪表板上的“固定到仪表板”复选框,然后选择“创建”********。Check the Pin to dashboard box to place your job on your dashboard and then select Create.

  6. 此时会在浏览器窗口右上角显示“正在部署...”通知。**You should see a Deployment in progress... notification displayed in the top right of your browser window.

配置作业输入 Configure job input

在此部分,需配置流分析作业的 IoT 中心设备输入。In this section, you will configure an IoT Hub device input to the Stream Analytics job. 使用在本快速入门的上一部分创建的 IoT 中心。Use the IoT Hub you created in the previous section of the quickstart.

  1. 导航到流分析作业。Navigate to your Stream Analytics job.

  2. 选择“输入” > “添加流输入” > “IoT 中心”。Select Inputs > Add Stream input > IoT Hub.

  3. 使用以下值填写“IoT 中心”页****:Fill out the IoT Hub page with the following values:

    设置Setting 建议的值Suggested value 说明Description
    输入别名Input alias IoTHubInputIoTHubInput 输入一个名称,用于标识作业的输入。Enter a name to identify the job’s input.
    订阅Subscription <Your subscription> 选择包含已创建的存储帐户的 Azure 订阅。Select the Azure subscription that has the storage account you created. 存储帐户可以在同一订阅中,也可以在另一订阅中。The storage account can be in the same or in a different subscription. 此示例假定已在同一订阅中创建存储帐户。This example assumes that you have created storage account in the same subscription.
    IoT 中心IoT Hub MyASAIoTHubMyASAIoTHub 输入在上一部分创建的 IoT 中心的名称。Enter the name of the IoT Hub you created in the previous section.
  4. 让其他选项保留默认值,然后选择“保存”以保存设置。****Leave other options to default values and select Save to save the settings.

    配置输入数据

配置作业输出Configure job output

  1. 导航到此前创建的的流分析作业。Navigate to the Stream Analytics job that you created earlier.

  2. 选择“输出” > “添加” > “Blob 存储”。Select Outputs > Add > Blob storage.

  3. 使用以下值填写“Blob 存储”页****:Fill out the Blob storage page with the following values:

    设置Setting 建议的值Suggested value 说明Description
    输出别名Output alias BlobOutputBlobOutput 输入一个名称,用于标识作业的输出。Enter a name to identify the job’s output.
    订阅Subscription <Your subscription> 选择包含已创建的存储帐户的 Azure 订阅。Select the Azure subscription that has the storage account you created. 存储帐户可以在同一订阅中,也可以在另一订阅中。The storage account can be in the same or in a different subscription. 此示例假定已在同一订阅中创建存储帐户。This example assumes that you have created storage account in the same subscription.
    存储帐户Storage account asaquickstartstorageasaquickstartstorage 选择或输入存储帐户的名称。Choose or enter the name of the storage account. 如果在同一订阅中创建存储帐户名称,则会自动将其删除。Storage account names are automatically detected if they are created in the same subscription.
    容器Container container1container1 选择你在存储帐户中创建的现有容器。Select the existing container that you created in your storage account.
  4. 让其他选项保留默认值,然后选择“保存”以保存设置。****Leave other options to default values and select Save to save the settings.

    配置输出

定义转换查询Define the transformation query

  1. 导航到此前创建的的流分析作业。Navigate to the Stream Analytics job that you created earlier.

  2. 选择“查询”****,然后更新查询,如下所示:Select Query and update the query as follows:

    SELECT *
    INTO BlobOutput
    FROM IoTHubInput
    HAVING Temperature > 27
    
  3. 在此示例中,查询从 IoT 中心读取数据,然后将其复制到 Blob 中的新文件。In this example, the query reads the data from IoT Hub and copies it to a new file in the blob. 选择“保存”。Select Save.

    配置作业转换

运行 IoT 模拟器Run the IoT simulator

  1. 打开 Raspberry Pi Azure IoT 联机模拟器Open the Raspberry Pi Azure IoT Online Simulator.

  2. 将第 15 行的占位符替换为在上一部分保存的 Azure IoT 中心设备连接字符串。Replace the placeholder in Line 15 with the Azure IoT Hub device connection string you saved in a previous section.

  3. 单击 “运行”Click Run. 输出会显示传感器数据和发送到 IoT 中心的消息。The output should show the sensor data and messages that are being sent to your IoT Hub.

    Raspberry Pi Azure IoT 联机模拟器

启动流分析作业并检查输出Start the Stream Analytics job and check the output

  1. 返回到作业概览页,然后选择“启动”。****Return to the job overview page and select Start.

  2. 对于“作业输出启动时间”字段,请在“启动作业”**** 下选择“现在”****。****Under Start job, select Now, for the Job output start time field. 然后选择“启动”,以便启动作业****。Then, select Start to start your job.

  3. 数分钟后,在门户中找到存储帐户以及此前已配置为作业输出的容器。After few minutes, in the portal, find the storage account & the container that you have configured as output for the job. 现在可以在容器中看到输出文件。You can now see the output file in the container. 此作业的首次启动需要数分钟的时间,但在启动后,只要有数据到达,它就会持续运行。The job takes a few minutes to start for the first time, after it is started, it will continue to run as the data arrives.

    转换的输出

清理资源Clean up resources

若不再需要资源组、流分析作业以及所有相关资源,请将其删除。When no longer needed, delete the resource group, the Stream Analytics job, and all related resources. 删除作业可避免对作业使用的流单元进行计费。Deleting the job avoids billing the streaming units consumed by the job. 如果计划在将来使用该作业,可以先停止它,等到以后需要时再重启它。If you're planning to use the job in future, you can stop it and restart it later when you need. 如果不打算继续使用该作业,请按照以下步骤删除本快速入门创建的所有资源:If you are not going to continue to use this job, delete all resources created by this quickstart by using the following steps:

  1. 在 Azure 门户的左侧菜单中选择“资源组”****,然后选择已创建资源的名称。From the left-hand menu in the Azure portal, select Resource groups and then select the name of the resource you created.

  2. 在资源组页上选择“删除”,在文本框中键入要删除的资源的名称,然后选择“删除”。**** ****On your resource group page, select Delete, type the name of the resource to delete in the text box, and then select Delete.

后续步骤Next steps

在本快速入门中,你使用 Azure 门户部署了一个简单的流分析作业。In this quickstart, you deployed a simple Stream Analytics job using Azure portal. 你还可以使用 PowerShell 部署流分析作业。You can also deploy Stream Analytics jobs using PowerShell.

若要了解如何配置其他输入源并执行实时检测,请继续阅读以下文章:To learn about configuring other input sources and performing real-time detection, continue to the following article: