使用模板通过事件中心创建一个命名空间并启用捕获Create a namespace with event hub and enable Capture using a template

本文介绍如何使用 Azure 资源管理器模板创建包含一个事件中心实例的事件中心命名空间,并在事件中心启用捕获功能This article shows how to use an Azure Resource Manager template that creates an Event Hubs namespace, with one event hub instance, and also enables the Capture feature on the event hub. 本文介绍如何定义要部署的资源以及如何定义执行部署时指定的参数。The article describes how to define which resources are deployed, and how to define parameters that are specified when the deployment is executed. 可将此模板用于自己的部署,或自定义此模板以满足要求。You can use this template for your own deployments, or customize it to meet your requirements.

本文还介绍如何根据所选目标,指定将事件捕获到 Azure 存储 Blob 或 Azure Data Lake Store 中。This article also shows how to specify that events are captured into either Azure Storage Blobs or an Azure Data Lake Store, based on the destination you choose.

有关创建模板的详细信息,请参阅创作 Azure 资源管理器模板For more information about creating templates, see Authoring Azure Resource Manager templates. 有关要在模板中使用的 JSON 语法和属性,请参阅 Microsoft.EventHub 资源类型For the JSON syntax and properties to use in a template, see Microsoft.EventHub resource types.

如需完整的模板,请单击以下 GitHub 链接:For the complete templates, click the following GitHub links:

备注

若要查看最新模板,请访问 Azure 快速入门模板库并搜索事件中心。To check for the latest templates, visit the Azure Quickstart Templates gallery and search for Event Hubs.

将部署什么内容?What will you deploy?

借助此模板,可以部署包含事件中心的事件中心命名空间并启用事件中心捕获With this template, you deploy an Event Hubs namespace with an event hub, and also enable Event Hubs Capture. 通过事件中心捕获,可以在所选的指定时间或大小间隔内,将事件中心的流数据自动传送到 Azure Blob 存储。Event Hubs Capture enables you to automatically deliver the streaming data in Event Hubs to Azure Blob storage, within a specified time or size interval of your choosing. 单击以下按钮,允许事件中心捕获将事件捕获到 Azure 存储中:Click the following button to enable Event Hubs Capture into Azure Storage:

部署到 AzureDeploy to Azure

parametersParameters

使用 Azure 资源管理器,可以定义在部署模板时想要指定的值的参数。With Azure Resource Manager, you define parameters for values you want to specify when the template is deployed. 模板包含名为 Parameters 的部分,其中包含所有参数值。The template includes a section called Parameters that contains all the parameter values. 应该为随着要部署的项目或要部署到的环境而变化的值定义参数。You should define a parameter for those values that vary based on the project you are deploying or based on the environment you are deploying to. 不要为始终保持不变的值定义参数。Do not define parameters for values that always stay the same. 每个参数值可在模板中用来定义所部署的资源。Each parameter value is used in the template to define the resources that are deployed.

模板定义以下参数。The template defines the following parameters.

eventHubNamespaceNameeventHubNamespaceName

要创建的事件中心命名空间的名称。The name of the Event Hubs namespace to create.

"eventHubNamespaceName":{  
     "type":"string",
     "metadata":{  
         "description":"Name of the EventHub namespace"
      }
}

eventHubNameeventHubName

在事件中心命名空间中创建的事件中心的名称。The name of the event hub created in the Event Hubs namespace.

"eventHubName":{  
    "type":"string",
    "metadata":{  
        "description":"Name of the event hub"
    }
}

messageRetentionInDaysmessageRetentionInDays

事件中心内消息的保留天数。The number of days to retain the messages in the event hub.

"messageRetentionInDays":{
    "type":"int",
    "defaultValue": 1,
    "minValue":"1",
    "maxValue":"7",
    "metadata":{
       "description":"How long to retain the data in event hub"
     }
 }

partitionCountpartitionCount

事件中心内创建的分区数。The number of partitions to create in the event hub.

"partitionCount":{
    "type":"int",
    "defaultValue":2,
    "minValue":2,
    "maxValue":32,
    "metadata":{
        "description":"Number of partitions chosen"
    }
 }

captureEnabledcaptureEnabled

在事件中心启用捕获。Enable Capture on the event hub.

"captureEnabled":{
    "type":"string",
    "defaultValue":"true",
    "allowedValues": [
    "false",
    "true"],
    "metadata":{
        "description":"Enable or disable the Capture for your event hub"
    }
 }

captureEncodingFormatcaptureEncodingFormat

指定用于序列化事件数据的编码格式。The encoding format you specify to serialize the event data.

"captureEncodingFormat":{
    "type":"string",
    "defaultValue":"Avro",
    "allowedValues":[
    "Avro"],
    "metadata":{
        "description":"The encoding format in which Capture serializes the EventData"
    }
}

captureTimecaptureTime

事件中心捕获开始捕获数据的时间间隔。The time interval in which Event Hubs Capture starts capturing the data.

"captureTime":{
    "type":"int",
    "defaultValue":300,
    "minValue":60,
    "maxValue":900,
    "metadata":{
         "description":"The time window in seconds for the capture"
    }
}

captureSizecaptureSize

捕获开始捕获数据的大小间隔。The size interval at which Capture starts capturing the data.

"captureSize":{
    "type":"int",
    "defaultValue":314572800,
    "minValue":10485760,
    "maxValue":524288000,
    "metadata":{
        "description":"The size window in bytes for capture"
    }
}

captureNameFormatcaptureNameFormat

事件中心捕获用来编写 Avro 文件的名称格式。The name format used by Event Hubs Capture to write the Avro files. 注意,捕获名称格式必须包含 {Namespace}{EventHub}{PartitionId}{Year}{Month}{Day}{Hour}{Minute}{Second} 字段。Note that a Capture name format must contain {Namespace}, {EventHub}, {PartitionId}, {Year}, {Month}, {Day}, {Hour}, {Minute}, and {Second} fields. 这些字段可以按任意顺序排列,可以带或不带分隔符。These can be arranged in any order, with or without delimiters.

"captureNameFormat": {
      "type": "string",
      "defaultValue": "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}",
      "metadata": {
        "description": "A Capture Name Format must contain {Namespace}, {EventHub}, {PartitionId}, {Year}, {Month}, {Day}, {Hour}, {Minute} and {Second} fields. These can be arranged in any order with or without delimeters. E.g.  Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}"
      }
    }
  

apiVersionapiVersion

模板的 API 版本。The API version of the template.

 "apiVersion":{  
    "type":"string",
    "defaultValue":"2017-04-01",
    "metadata":{  
        "description":"ApiVersion used by the template"
    }
 }

如果选择 Azure 存储作为目标,请使用以下参数。Use the following parameters if you choose Azure Storage as your destination.

destinationStorageAccountResourceIddestinationStorageAccountResourceId

捕获需要 Azure 存储帐户资源 ID,以启用到所需存储帐户的捕获。Capture requires an Azure Storage account resource ID to enable capturing to your desired Storage account.

 "destinationStorageAccountResourceId":{
    "type":"string",
    "metadata":{
        "description":"Your existing Storage account resource ID where you want the blobs be captured"
    }
 }

blobContainerNameblobContainerName

用于捕获事件数据的 Blob 容器。The blob container in which to capture your event data.

 "blobContainerName":{
    "type":"string",
    "metadata":{
        "description":"Your existing storage container in which you want the blobs captured"
    }
}

要针对 Azure 存储(作为已捕获事件的目标)进行部署的资源Resources to deploy for Azure Storage as destination to captured events

创建包含一个事件中心的 EventHub 类型的命名空间,并启用“捕获到 Azure Blob 存储”。Creates a namespace of type EventHub, with one event hub, and also enables Capture to Azure Blob Storage.

"resources":[  
      {  
         "apiVersion":"[variables('ehVersion')]",
         "name":"[parameters('eventHubNamespaceName')]",
         "type":"Microsoft.EventHub/Namespaces",
         "location":"[variables('location')]",
         "sku":{  
            "name":"Standard",
            "tier":"Standard"
         },
         "resources": [
    {
      "apiVersion": "2017-04-01",
      "name": "[parameters('eventHubNamespaceName')]",
      "type": "Microsoft.EventHub/Namespaces",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "isAutoInflateEnabled": "true",
        "maximumThroughputUnits": "7"
      },
      "resources": [
        {
          "apiVersion": "2017-04-01",
          "name": "[parameters('eventHubName')]",
          "type": "EventHubs",
          "dependsOn": [
            "[concat('Microsoft.EventHub/namespaces/', parameters('eventHubNamespaceName'))]"
          ],
          "properties": {
            "messageRetentionInDays": "[parameters('messageRetentionInDays')]",
            "partitionCount": "[parameters('partitionCount')]",
            "captureDescription": {
              "enabled": "true",
              "skipEmptyArchives": false,
              "encoding": "[parameters('captureEncodingFormat')]",
              "intervalInSeconds": "[parameters('captureTime')]",
              "sizeLimitInBytes": "[parameters('captureSize')]",
              "destination": {
                "name": "EventHubArchive.AzureBlockBlob",
                "properties": {
                  "storageAccountResourceId": "[parameters('destinationStorageAccountResourceId')]",
                  "blobContainer": "[parameters('blobContainerName')]",
                  "archiveNameFormat": "[parameters('captureNameFormat')]"
                }
              }
            }
          }

        }
      ]
    }
  ]

运行部署的命令Commands to run deployment

要将资源部署到 Azure,必须登录到 Azure 帐户,并且必须使用 Azure 资源管理器模块。To deploy the resources to Azure, you must be signed in to your Azure account and you must use the Azure Resource Manager module. 若要了解配合使用 Azure 资源管理器和 Azure PowerShell 或 Azure CLI 的相关信息,请参阅:To learn about using Azure Resource Manager with either Azure PowerShell or Azure CLI, see:

以下示例假定帐户中已具有一个指定名称的资源组。The following examples assume you already have a resource group in your account with the specified name.

PowerShellPowerShell

备注

本文进行了更新,以便使用新的 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.

部署模板,允许事件中心捕获将事件捕获到 Azure 存储中:Deploy your template to enable Event Hubs Capture into Azure Storage:

New-AzResourceGroupDeployment -ResourceGroupName \<resource-group-name\> -TemplateFile https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-eventhubs-create-namespace-and-enable-capture/azuredeploy.json

Azure CLIAzure CLI

Azure Blob 存储(作为目标):Azure Blob Storage as destination:

azure config mode arm

azure group deployment create \<my-resource-group\> \<my-deployment-name\> --template-uri [https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-eventhubs-create-namespace-and-enable-capture/azuredeploy.json][]

后续步骤Next steps

也可通过 Azure 门户配置事件中心捕获。You can also configure Event Hubs Capture via the Azure portal. 有关详细信息,请参阅通过 Azure 门户启用事件中心捕获For more information, see Enable Event Hubs Capture using the Azure portal.

访问以下链接可以了解有关事件中心的详细信息:You can learn more about Event Hubs by visiting the following links: