使用範本來建立含有事件中樞的命名空間並啟用擷取

本文說明如何使用 Azure Resource Manager 範本來建立含有一個事件中樞執行個體的事件中樞命名空間,也可在該事件中樞上啟用擷取功能。 此文章說明如何定義要部署哪些資源,以及如何定義執行部署時所指定的參數。 您可以直接在自己的部署中使用此範本,或自訂此範本以符合您的需求。

本文也會示範如何根據您選擇的目的地,指定將事件擷取到 Azure 儲存體 Blob 或 Azure Data Lake Store 中。

如需關於建立範本的詳細資訊,請參閱 編寫 Azure Resource Manager 範本。 如需要在範本中使用的 JSON 語法和屬性,請參閱 Microsoft.EventHub 資源類型

如需 Azure 資源命名慣例相關模式和實務的詳細資訊,請參閱 Azure 資源命名慣例

如需所有範本,請選取下列 GitHub 連結:

注意

若要檢查最新的範本,請造訪 Azure 快速入門範本 資源庫並搜尋事件中樞。

重要

Azure Data Lake 儲存體 Gen1 已淘汰,因此請勿使用它來擷取事件數據。 如需詳細資訊,請參閱官方公告。 如果您使用 Azure Data Lake 儲存體 Gen1,請移轉至 Azure Data Lake 儲存體 Gen2。 如需詳細資訊,請參閱 Azure Data Lake Storage 移轉指導方針和模式

您將部署什麼?

使用此範本,您可部署含有事件中樞的事件中樞命名空間,也可啟用事件中樞擷取。 Azure 事件中樞擷取可讓您將事件中樞的資料,在您選擇的指定時間範圍或大小間隔內,自動串流至 Azure Blob 儲存體或 Azure Data Lake Store。 選取以下按鈕以啟用「事件中樞擷取到 Azure 儲存體中」:

部署至 Azure

選取以下按鈕以啟用「事件中樞擷取到 Azure Data Lake Store 中」:

部署至 Azure

參數

透過 Azure 資源管理員,您可以定義在部署範本時想要指定之值的參數。 此範本有一個 Parameters 區段,內含所有參數值。 建議根據會隨要部署的專案或要部署的目標環境而變化的值,定義參數。 請不要為永遠保持不變的值定義參數。 每個參數值都可在範本中用來定義所部署的資源。

範本會定義下列參數。

eventHubNamespaceName

要建立的事件中樞命名空間名稱。

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

eventHubName

在「事件中樞」命名空間中建立的事件中樞名稱。

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

messageRetentionInDays

要在事件中樞中保留訊息的天數。

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

partitionCount

要在事件中樞中建立的資料分割數目。

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

captureEnabled

在事件中樞上啟用封存擷取功能。

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

captureEncodingFormat

您指定用來將事件資料序列化的編碼格式。

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

captureTime

事件中樞擷取功能開始擷取資料的時間間隔。

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

captureSize

擷取功能開始擷取資料的大小間隔。

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

captureNameFormat

事件中樞擷取功能用來寫入 Avro 檔案的名稱格式。 擷取名稱格式必須包含{Namespace}{EventHub}{Hour}{PartitionId}{Month}{Year}{Day}、、 {Minute}{Second} 欄位。 這些欄位可以依任何順序排列,無論是否有分隔符。

"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}"
      }
    }

apiVersion

範本的 API 版本。

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

如果您選擇 Azure 儲存體作為目的地,請使用下列參數。

destinationStorageAccountResourceId

擷取功能需要有 Azure 儲存體帳戶資源識別碼,才能為您所需的儲存體帳戶啟用擷取功能。

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

blobContainerName

用來擷取存事件資料的 blob 容器。

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

subscriptionId

事件中樞命名空間和 Azure Data Lake Store 的訂用帳戶 ID。 這兩個資源都必須屬於同一個訂用帳戶識別碼。

"subscriptionId": {
    "type": "string",
    "metadata": {
        "description": "Subscription ID of both Azure Data Lake Store and Event Hubs namespace"
     }
 }

dataLakeAccountName

已擷取事件的 Azure Data Lake Store 名稱。

"dataLakeAccountName": {
    "type": "string",
    "metadata": {
        "description": "Azure Data Lake Store name"
    }
}

dataLakeFolderPath

已擷取事件的目的地資料夾路徑。 此路徑是 Data Lake Store 中事件在擷取作業期間推送至的資料夾。 若要在此資料夾上設定權限,請參閱使用 Azure Data Lake Store 從事件中樞擷取資料

"dataLakeFolderPath": {
    "type": "string",
    "metadata": {
        "description": "Destination capture folder path"
    }
}

以 Azure 儲存體或 Azure Data Lake Storage Gen2 為目的地

使用一個事件中樞建立 類型的Microsoft.EventHub/Namespaces命名空間,並啟用擷取 Azure Blob 儲存體 或 Azure Data Lake 儲存體 Gen2。

"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')]"
                }
              }
            }
          }

        }
      ]
    }
  ]

執行部署的命令

若要將資源部署至 Azure,您必須登入 Azure 帳戶,而且必須使用 Azure Resource Manager 模組。 若要了解如何搭配使用 Azure 資源管理員與 Azure PowerShell 或 Azure CLI,請參閱:

下例假設您的帳戶中已經有已指定名稱的資源群組。

PowerShell

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

部署您的範本,以啟用「事件中樞擷取至 Azure 儲存體」功能:

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

部署您的範本,以啟用「事件中樞擷取至 Azure Data Lake Store」功能:

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

Azure CLI

Azure Blob 儲存體作為目的地:

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

Azure Data Lake Store 作為目的地:

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

下一步

您也可以透過 Azure 入口網站設定事件中樞擷取功能。 如需詳細資訊,請參閱使用 Azure 入口網站啟用事件中樞擷取功能

您可以造訪下列連結以深入了解事件中樞︰