快速入门:使用资源管理器模板创建通知中心

Azure 通知中心提供易于使用且横向扩展的推送引擎,允许你从任何后端(云或本地)向任何平台(iOS、Android、Windows、Kindle 等)发送通知。 有关此服务的详细信息,请参阅什么是 Azure 通知中心

资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 模板使用声明性语法。 在声明性语法中,你可以在不编写创建部署的编程命令序列的情况下,描述预期部署。

本快速入门使用 Azure 资源管理器模板来创建 Azure 通知中心命名空间,并在命名空间中创建名为“MyHub”的通知中心。

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。 Azure 门户中会打开模板。

部署到 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.4.1272.37030",
      "templateHash": "6172359878293479971"
    }
  },
  "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”的通知中心。

部署到 Azure

查看已部署的资源

可以使用 Azure 门户来检查已部署的资源,也可以使用 Azure CLI 或 Azure PowerShell 脚本列出已部署的通知中心命名空间和中心:

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

输出如下所示:

验证部署


清理资源

如果不再需要资源组,可以将其删除,这将删除资源组中的资源。

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

后续步骤

有关引导你完成模板创建过程的分步教程,请参阅: