Share via


快速入門:使用 Resource Manager 範本建立通知中樞

Azure 通知中樞提供易於使用且相應放大的推播引擎,可讓您從任何後端 (雲端或內部部署) 傳送通知到任何平台 (iOS、Android、Windows、Kindle 等)。 如需該服務的詳細資訊,請參閱什麼是 Azure 通知中樞

Azure Resource Manager 範本是 JavaScript 物件表示法 (JSON) 檔案,可定義專案的基礎結構和組態。 範本使用宣告式語法。 您不需要撰寫程式設計命令順序來建立部署,即可描述預定的部署。

本快速入門會使用 Azure Resource Manager 範本來建立 Azure 通知中樞命名空間,以及該命名空間內名為 MyHub 的通知中樞。

如果您的環境符合必要條件,而且您很熟悉 ARM 範本,請選取 [部署至 Azure] 按鈕。 範本會在 Azure 入口網站中開啟。

Button to deploy the Resource Manager template to Azure.

必要條件

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶

檢閱範本

本快速入門中使用的範本是來自 Azure 快速入門範本

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.8.9.13224",
      "templateHash": "2713724900359552876"
    }
  },
  "parameters": {
    "namespaceName": {
      "type": "string",
      "metadata": {
        "description": "The name of the Notification Hubs namespace."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "The location in which the Notification Hubs resources should be deployed."
      }
    }
  },
  "variables": {
    "hubName": "MyHub"
  },
  "resources": [
    {
      "type": "Microsoft.NotificationHubs/namespaces",
      "apiVersion": "2017-04-01",
      "name": "[parameters('namespaceName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Free"
      }
    },
    {
      "type": "Microsoft.NotificationHubs/namespaces/notificationHubs",
      "apiVersion": "2017-04-01",
      "name": "[format('{0}/{1}', parameters('namespaceName'), variables('hubName'))]",
      "location": "[parameters('location')]",
      "properties": {},
      "dependsOn": [
        "[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaceName'))]"
      ]
    }
  ]
}

部署範本

選取以下影像來登入 Azure 並開啟範本。 範本會採用通知中樞命名空間的名稱做為參數。 然後範本會建立具有該名稱的命名空間,以及該命名空間內名為 MyHub 的通知中樞。

Button to deploy the Resource Manager template to Azure.

檢閱已部署的資源

您可以使用 Azure 入口網站來檢查已部署的資源,或使用 Azure CLI 或 Azure PowerShell 指令碼來列出已部署的通知中樞命名空間和中樞:

Get-AzNotificationHub -Namespace "nhtestns123" -ResourceGroup "ContosoNotificationsGroup"
Get-AzNotificationHubsNamespace -Namespace "nhtestns123"

輸出大致如下:

Verify deployment


清除資源

如果不再需要,請刪除資源群組,這會刪除資源群組中的資源。

$resourceGroupName = Read-Host -Prompt "Enter the resource group name"
Remove-AzResourceGroup -Name $resourceGroupName
Write-Host "Press [ENTER] to continue..."

下一步

如需逐步教學課程,以引導您完成建立範本的流程,請參閱: