快速入门:使用 ARM 模板创建事件中心Quickstart: Create an event hub by using an ARM template

Azure 事件中心是一个大数据流式处理平台和事件引入服务,每秒能够接收和处理数百万个事件。Azure Event Hubs is a Big Data streaming platform and event ingestion service, capable of receiving and processing millions of events per second. 事件中心可以处理和存储分布式软件和设备生成的事件、数据或遥测。Event Hubs can process and store events, data, or telemetry produced by distributed software and devices. 可以使用任何实时分析提供程序或批处理/存储适配器转换和存储发送到数据中心的数据。Data sent to an event hub can be transformed and stored using any real-time analytics provider or batching/storage adapters. 有关事件中心的详细概述,请参阅事件中心概述事件中心功能For detailed overview of Event Hubs, see Event Hubs overview and Event Hubs features. 本快速入门将使用 Azure 资源管理器模板(ARM 模板)创建事件中心。In this quickstart, you create an event hub by using an Azure Resource Manager template (ARM template). 然后部署 ARM 模板,以创建包含一个事件中心的事件中心类型的命名空间。You deploy an ARM template to create a namespace of type Event Hubs, with one event hub.

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Azure 门户中会打开模板。The template will open in the Azure portal.

部署到 AzureDeploy to Azure

先决条件Prerequisites

如果没有 Azure 订阅,请在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

查看模板Review the template

本快速入门中使用的模板来自 Azure 快速启动模板The template used in this quickstart is from Azure Quickstart Templates.

{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion":"1.0.0.0", "parameters": { "projectName":{ "type": "string", "metadata": { "description":"指定用于生成事件中心名称和命名空间名称的项目名称。"{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "projectName":{ "type": "string", "metadata": { "description": "Specifies a project name that is used to generate the Event Hub name and the Namespace name." } }, "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description":"指定所有资源的 Azure 位置。"} }, "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description": "Specifies the Azure location for all resources." } }, "eventHubSku": { "type": "string", "allowedValues": [ "Basic", "Standard" ], "defaultValue":"Standard", "metadata": { "description":"指定服务总线命名空间的消息传递层。"} }, "eventHubSku": { "type": "string", "allowedValues": [ "Basic", "Standard" ], "defaultValue": "Standard", "metadata": { "description": "Specifies the messaging tier for service Bus namespace." } } }, "variables": { "eventHubNamespaceName": "[concat(parameters('projectName'), 'ns')]", "eventHubName": "[parameters('projectName')]" }, "resources": [ { "apiVersion":"2017-04-01", "type":"Microsoft.EventHub/namespaces", "name": "[variables('eventHubNamespaceName')]", "location": "[parameters('location')]", "sku": { "name": "[parameters('eventHubSku')]", "tier": "[parameters('eventHubSku')]", "capacity":1 }, "properties": { "isAutoInflateEnabled": false, "maximumThroughputUnits":0 } }, { "apiVersion":"2017-04-01", "type":"Microsoft.EventHub/namespaces/eventhubs", "name": "[concat(variables('eventHubNamespaceName'), '/', variables('eventHubName'))]", "location": "[parameters('location')]", "dependsOn": [ "[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]" ], "properties": { "messageRetentionInDays":7, "partitionCount":1 } } ] }} } }, "variables": { "eventHubNamespaceName": "[concat(parameters('projectName'), 'ns')]", "eventHubName": "[parameters('projectName')]" }, "resources": [ { "apiVersion": "2017-04-01", "type": "Microsoft.EventHub/namespaces", "name": "[variables('eventHubNamespaceName')]", "location": "[parameters('location')]", "sku": { "name": "[parameters('eventHubSku')]", "tier": "[parameters('eventHubSku')]", "capacity": 1 }, "properties": { "isAutoInflateEnabled": false, "maximumThroughputUnits": 0 } }, { "apiVersion": "2017-04-01", "type": "Microsoft.EventHub/namespaces/eventhubs", "name": "[concat(variables('eventHubNamespaceName'), '/', variables('eventHubName'))]", "location": "[parameters('location')]", "dependsOn": [ "[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]" ], "properties": { "messageRetentionInDays": 7, "partitionCount": 1 } } ] }


The resources defined in the template include:

- [**Microsoft.EventHub/namespaces**](https://docs.microsoft.com/azure/templates/microsoft.eventhub/namespaces)
- [**Microsoft.EventHub/namespaces/eventhubs**](https://docs.microsoft.com/azure/templates/microsoft.eventhub/namespaces/eventhubs)

To find more template samples, see [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/?term=eventhub&pageNumber=1&sort=Popular).

## Deploy the template

To deploy the template:

1. Sign in to the Azure PowerShell.

   ```azurepowershell
   $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
   $location = Read-Host -Prompt "Enter the location (i.e. chinaeast)"
   $resourceGroupName = "${projectName}rg"
   $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-eventhubs-create-namespace-and-eventhub/azuredeploy.json"

   New-AzResourceGroup -Name $resourceGroupName -Location $location
   New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -projectName $projectName

   Write-Host "Press [ENTER] to continue ..."

创建事件中心需要一些时间。It takes a few moments to create an event hub.

  1. 选择“复制”以复制 PowerShell 脚本。Select Copy to copy the PowerShell script.
  2. 右键单击 shell 控制台并选择“粘贴”。Right-click the shell console, and then select Paste.

验证部署Validate the deployment

若要验证部署,可以从 Azure 门户打开资源组,或使用以下 Azure PowerShell 脚本。To verify the deployment, you can either open the resource group from the Azure portal, or use the following Azure PowerShell script.

$projectName = Read-Host -Prompt "Enter the same project name that you used in the last procedure"
$resourceGroupName = "${projectName}rg"
$namespaceName = "${projectName}ns"

Get-AzEventHub -ResourceGroupName $resourceGroupName -Namespace $namespaceName

Write-Host "Press [ENTER] to continue ..."

清理资源Clean up resources

不再需要 Azure 资源时,请通过删除资源组来清理部署的资源。When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.

$projectName = Read-Host -Prompt "Enter the same project name that you used in the last procedure"
$resourceGroupName = "${projectName}rg"

Remove-AzResourceGroup -ResourceGroupName $resourceGroupName

Write-Host "Press [ENTER] to continue ..."

后续步骤Next steps

在本文中,你已创建一个事件中心命名空间,并在该命名空间中创建了一个事件中心。In this article, you created an Event Hubs namespace, and an event hub in the namespace. 有关如何将事件发送到事件中心(或)从事件中心接收事件的分步说明,请参阅“发送和接收事件”教程:For step-by-step instructions to send events to (or) receive events from an event hub, see the Send and receive events tutorials: