빠른 시작: ARM 템플릿을 사용하여 이벤트 허브 만들기

이 빠른 시작에서는 ARM 템플릿(Azure Resource Manager 템플릿)을 사용하여 이벤트 허브를 만듭니다. 이벤트 허브가 하나 있는 Event Hubs 형식의 네임스페이스를 만드는 ARM 템플릿을 배포합니다.

필수 조건

템플릿 검토

이 빠른 시작에서 사용되는 템플릿은 Azure 빠른 시작 템플릿에서 나온 것입니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.5.6.12127",
      "templateHash": "16940368634879422816"
    }
  },
  "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": "Specifies the Azure location for all resources."
      }
    },
    "eventHubSku": {
      "type": "string",
      "defaultValue": "Standard",
      "allowedValues": [
        "Basic",
        "Standard"
      ],
      "metadata": {
        "description": "Specifies the messaging tier for Event Hub Namespace."
      }
    }
  },
  "variables": {
    "eventHubNamespaceName": "[format('{0}ns', parameters('projectName'))]",
    "eventHubName": "[parameters('projectName')]"
  },
  "resources": [
    {
      "type": "Microsoft.EventHub/namespaces",
      "apiVersion": "2021-11-01",
      "name": "[variables('eventHubNamespaceName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('eventHubSku')]",
        "tier": "[parameters('eventHubSku')]",
        "capacity": 1
      },
      "properties": {
        "isAutoInflateEnabled": false,
        "maximumThroughputUnits": 0
      }
    },
    {
      "type": "Microsoft.EventHub/namespaces/eventhubs",
      "apiVersion": "2021-11-01",
      "name": "[format('{0}/{1}', variables('eventHubNamespaceName'), variables('eventHubName'))]",
      "properties": {
        "messageRetentionInDays": 7,
        "partitionCount": 1
      },
      "dependsOn": [
        "[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]"
      ]
    }
  ]
}

템플릿에 정의된 리소스는 다음과 같습니다.

더 많은 샘플 템플릿은 Azure 빠른 시작 템플릿에서 찾을 수 있습니다.

템플릿 배포

Azure Portal 사용자 인터페이스 사용

  1. 환경이 필수 구성 요소를 충족하고 ARM 템플릿 사용에 익숙한 경우 Azure에 배포 단추를 선택합니다. 그러면 Azure Portal에서 템플릿이 열립니다.

    Button to deploy the Resource Manager template to Azure.

  2. 기존 리소스 그룹을 선택하거나 리소스 그룹을 만들고 선택합니다.

  3. 지역을 선택합니다.

  4. 프로젝트의 고유한 이름을 입력합니다. 이 이름은 Event Hubs 네임스페이스와 네임스페이스의 이벤트 허브에 대한 이름을 생성하는 데 사용됩니다.

  5. 검토 + 만들기를 선택합니다.

  6. 리뷰 + 생성 페이지에서 생성를 선택합니다.

Azure Cloud Shell 사용

Azure Cloud Shell을 사용하여 템플릿을 배포하려면:

  1. 다음 코드 블록에서 Cloud Shell 열기를 선택한 다음, 지침에 따라 Azure Cloud Shell에 로그인합니다.

    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location (i.e. centralus)"
    $resourceGroupName = "${projectName}rg"
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.eventhub/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 ..."
    

    이벤트 허브를 만드는 데 몇 분 정도 걸립니다.

  2. 복사를 선택하여 PowerShell 스크립트를 복사합니다.

  3. 셸 콘솔 창을 마우스 오른쪽 단추로 클릭하고 붙여넣기를 선택합니다.

  4. Enter 키를 눌러 명령을 실행합니다.

배포 유효성 검사

배포를 확인하려면 Azure Portal에서 리소스 그룹을 열거나 다음 Azure PowerShell 스크립트를 사용하면 됩니다. Cloud Shell이 아직 열려 있으면 첫 번째 줄(Read-Host)을 복사/실행할 필요가 없습니다.

$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 ..."

리소스 정리

Azure 리소스가 더 이상 필요하지 않은 경우 리소스 그룹을 삭제하여 배포한 리소스를 정리합니다. Cloud Shell이 아직 열려 있으면 첫 번째 줄(Read-Host)을 복사/실행할 필요가 없습니다.

$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 ..."

다음 단계

이 문서에서는 Event Hubs 네임스페이스 및 네임스페이스의 이벤트 허브를 만들었습니다. 이벤트 허브에서 이벤트를 보내거나 받기 위한 단계별 지침은 이벤트 보내기 및 받기 자습서를 참조하세요.