将 IoT 中心事件源添加到 Azure 时序见解环境Add an IoT hub event source to your Azure Time Series Insight environment

本文介绍如何使用 Azure 门户将从 Azure IoT 中心读取数据的事件源添加到 Azure 时序见解环境。This article describes how to use the Azure portal to add an event source that reads data from Azure IoT Hub to your Azure Time Series Insights environment.

备注

本文中的说明对于 Azure 时序见解第 1 代和 Azure 时序见解第 2 代环境都适用。The instructions in this article apply both to Azure Time Series Insights Gen 1 and to Azure Time Series Insight Gen 2 environments.

先决条件Prerequisites

  • 创建 Azure 时序见解环境Create an Azure Time Series Insights environment.
  • 使用 Azure 门户创建 IoT 中心Create an IoT hub by using the Azure portal.
  • IoT 中心必须有正在发送进来的活动消息事件。The IoT hub must have active message events being sent in.
  • 在 IoT 中心创建专用使用者组,以供 Azure 时序见解环境使用。Create a dedicated consumer group in the IoT hub for the Azure Time Series Insight environment to consume from. 每个 Azure 时序见解事件源都必须具有自己的专用使用者组,该组不与其他使用者共享。Each Azure Time Series Insight event source must have its own dedicated consumer group that isn't shared with any other consumer. 如果多个读取器使用同一使用者组中的事件,则所有读取器都可能出现故障。If multiple readers consume events from the same consumer group, all readers are likely to exhibit failures. 有关详细信息,请阅读 Azure IoT 中心开发人员指南For details, read the Azure IoT Hub developer guide.

将使用者组添加到 IoT 中心Add a consumer group to your IoT hub

应用程序使用使用者组从 Azure IoT 中心提取数据。Applications use consumer groups to pull data from Azure IoT Hub. 若要可靠地从 IoT 中心读取数据,请提供一个专用的使用者组,仅供此 Azure 时序见解环境使用。To reliably read data from your IoT hub, provide a dedicated consumer group that's used only by this Azure Time Series Insight environment.

若要将新的使用者组添加到 IoT 中心,请执行以下操作:To add a new consumer group to your IoT hub:

  1. Azure 门户中,查找并打开 IoT 中心。In the Azure portal, find and open your IoT hub.

  2. 在“设置”下,选择“内置终结点”,然后选择“事件”终结点。Under Settings, select Built-in Endpoints, and then select the Events endpoint.

    在“内置终结点”页上,选择“事件”按钮On the Build-in Endpoints page, select the Events button

  3. 在“使用者组”下,为使用者组输入唯一名称。Under Consumer groups, enter a unique name for the consumer group. 创建新的事件源时,请在 Azure 时序见解环境中使用此相同名称。Use this same name in your Azure Time Series Insight environment when you create a new event source.

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

添加新的事件源Add a new event source

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

  2. 在左侧菜单中,选择“所有资源” 。In the left menu, select All resources. 选择 Azure 时序见解环境。Select your Azure Time Series Insight environment.

  3. 在“设置”下,依次选择“事件源”、“添加”。 Under Settings, select Event Sources, and then select Add.

    选择“事件源”,然后选择“添加”按钮Select Event Sources, and then select the Add button

  4. 在“新建事件源”窗格中,输入一个特定于此 Azure 时序见解环境的名称作为“事件源名称”。In the New event source pane, for Event source name, enter a name that's unique to this Azure Time Series Insight environment. 例如,输入 event-streamFor example, enter event-stream.

  5. 选择“IoT 中心”作为“源”。For Source, select IoT Hub.

  6. 为“导入选项”选择一个值:Select a value for Import option:

    • 在其中一个订阅上已有 IoT 中心时,请选择“从可用订阅使用 IoT 中心”。If you already have an IoT hub in one of your subscriptions, select Use IoT Hub from available subscriptions. 此选项是最简单的方法。This option is the easiest approach.

      在“新建事件源”窗格中选择选项Select options in the New event source pane

    • 下表介绍的属性是“通过可用订阅使用 IoT 中心” 选项所需的:The following table describes the properties that are required for the Use IoT Hub from available subscriptions option:

      “新建事件源”窗格 - 需要在“通过可用订阅使用 IoT 中心”选项中设置的属性New event source pane - Properties to set in the Use IoT Hub from available subscriptions option

      属性Property 说明Description
      订阅Subscription 所需的 iot 中心所属的订阅。The subscription the desired iot hub belongs to.
      IoT 中心名称IoT hub name 所选 iot 中心的名称。The name of the selected iot hub.
      IoT 中心策略名称IoT hub policy name 选择共享访问策略。Select the shared access policy. 可以在 IoT 中心设置选项卡上找到共享访问策略。每个共享访问策略具有名称、所设权限以及访问密钥。You can find the shared access policy on the IoT hub settings tab. Each shared access policy has a name, permissions that you set, and access keys. 事件源的共享访问策略必须具有服务连接权限**。The shared access policy for your event source must have service connect permissions.
      IoT 中心策略密钥IoT hub policy key 密钥已预填充。The key is prepopulated.
    • 如果 IoT 中心在订阅外部,或者你希望选择高级选项,请选择“手动提供 IoT 中心设置”。If the IoT hub is external to your subscriptions, or if you want to choose advanced options, select Provide IoT Hub settings manually.

      下表介绍“手动提供 IoT 中心设置” 所需的属性:The following table describes the required properties for the Provide IoT Hub settings manually:

      属性Property 描述Description
      订阅 IDSubscription ID 所需的 iot 中心所属的订阅。The subscription the desired iot hub belongs to.
      资源组Resource group 在其中创建了此 IoT 中心的资源组名称。The resource group name in which the IoT hub was created.
      IoT 中心名称IoT hub name IoT 中心的名称。The name of your IoT hub. 创建 IoT 中心时,为 IoT 中心输入了一个名称。When you created your IoT hub, you entered a name for the IoT hub.
      IoT 中心策略名称IoT hub policy name 共享访问策略。The shared access policy. 可以在 IoT 中心设置选项卡上创建共享访问策略。每个共享访问策略具有名称、所设权限以及访问密钥。You can create the shared access policy on the IoT hub settings tab. Each shared access policy has a name, permissions that you set, and access keys. 事件源的共享访问策略必须具有服务连接权限**。The shared access policy for your event source must have service connect permissions.
      IoT 中心策略密钥IoT hub policy key 用于对 Azure 服务总线命名空间的访问权限进行身份验证的共享访问密钥。The shared access key that's used to authenticate access to the Azure Service Bus namespace. 在此处输入主密钥或辅助密钥。Enter the primary or secondary key here.
    • 这两个选项共享以下配置选项:Both options share the following configuration options:

      属性Property 描述Description
      IoT 中心使用者组IoT hub consumer group 从 IoT 中心读取事件的使用者组。The consumer group that reads events from the IoT hub. 强烈建议为事件源使用专用的使用者组。We highly recommend that you use a dedicated consumer group for your event source.
      事件序列化格式Event serialization format 目前,JSON 是唯一可用的序列化格式。Currently, JSON is the only available serialization format. 事件消息必须采用此格式,否则将无法读取任何数据。The event messages must be in this format or no data can be read.
      时间戳属性名称Timestamp property name 若要确定此值,需要了解发送到 IoT 中心的消息数据的消息格式。To determine this value, you need to understand the message format of the message data that's sent to the IoT hub. 此值是 消息数据中你想要用作事件时间戳的特定事件属性的“名称”。This value is the name of the specific event property in the message data that you want to use as the event timestamp. 该值区分大小写。The value is case-sensitive. 如果留空,则事件源中的“事件排队时间” 将用作事件时间戳。If left blank, the event enqueue time in the event source is used as the event timestamp.
  7. 添加已添加到 IoT 中心的专用 Azure 时序见解使用者组名称。Add the dedicated Azure Time Series Insight consumer group name that you added to your IoT hub.

  8. 选择“创建”。Select Create.

  9. 创建事件源以后,Azure 时序见解就会自动开始将数据流式传输到环境中。After you create the event source, Azure Time Series Insight automatically starts streaming data to your environment.

后续步骤Next steps