快速入门:使用 ARM 模板创建通知中心Quickstart: Create a notification hub using an ARM template

Azure 通知中心提供易于使用且横向扩展的推送引擎,允许你从任何后端(云或本地)向任何平台(iOS、Android、Windows、Kindle 等)发送通知。Azure Notification Hubs provides an easy-to-use and scaled-out push engine that enables you to send notifications to any platform (iOS, Android, Windows, Kindle, etc.) from any backend (cloud or on-premises). 有关此服务的详细信息,请参阅什么是 Azure 通知中心For more information about the service, see What is Azure Notification Hubs.

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.

本快速入门使用 Azure 资源管理器模板(ARM 模板)来创建 Azure 通知中心命名空间,并在命名空间中创建名为“MyHub”的通知中心。This quickstart uses an Azure Resource Manager template (ARM template) to create an Azure Notification Hubs namespace, and a notification hub named MyHub within that namespace.

如果你的环境满足先决条件,并且你熟悉如何使用 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/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "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": [
        {
            "apiVersion": "2017-04-01",
            "name": "[parameters('namespaceName')]",
            "type": "Microsoft.NotificationHubs/namespaces",
            "location": "[parameters('location')]",
            "kind": "NotificationHub",
            "sku": {
                "name": "Free"
            },
            "resources": [
                {
                    "name": "[concat(parameters('namespaceName'), '/', variables('hubName'))]",
                    "apiVersion": "2017-04-01",
                    "type": "Microsoft.NotificationHubs/namespaces/notificationHubs",
                    "location": "[parameters('location')]",
                    "dependsOn": [
                        "[parameters('namespaceName')]"
                    ]
                }
            ]
        }
    ]
}

部署模板Deploy the template

选择下图登录到 Azure 并打开一个模板。Select the following image to sign in to Azure and open a template. 模板采用通知中心命名空间名称作为参数。The template takes a Notification Hubs namespace name as a parameter. 然后,该模板创建一个具有该名称的命名空间,并在该命名空间中创建名为“MyHub”的通知中心。The template then creates a namespace with that name and a notification hub named MyHub within that namespace.

“部署到 Azure”Deploy to Azure

查看已部署的资源Review deployed resources

可以使用 Azure 门户来检查已部署的资源,也可以使用 Azure CLI 或 Azure PowerShell 脚本列出已部署的通知中心命名空间和中心:You can either use the Azure portal to check the deployed resources, or use Azure CLI or Azure PowerShell script to list the deployed Notification Hubs namespace and hub:

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