使用 Azure Resource Manager 模板创建包含主题和订阅的服务总线命名空间Create a Service Bus namespace with topic and subscription using an Azure Resource Manager template

本文介绍如何使用 Azure Resource Manager 模板创建服务总线命名空间,并且该命名空间内包含主题和订阅。This article shows how to use an Azure Resource Manager template that creates a Service Bus namespace and a topic and subscription within that namespace. 本文介绍如何指定要部署的资源以及如何定义执行部署时指定的参数。The article explains how to specify which resources are deployed and how to define parameters that are specified when the deployment is executed. 可将此模板用于自己的部署,或自定义此模板以满足要求You can use this template for your own deployments, or customize it to meet your requirements

有关创建模板的详细信息,请参阅创作 Azure 资源管理器模板For more information about creating templates, see Authoring Azure Resource Manager templates.

有关完整的模板,请参阅 包含主题和订阅的服务总线命名空间 模板。For the complete template, see the Service Bus namespace with topic and subscription template.

Note

以下 Azure Resource Manager 模板可供下载和部署。The following Azure Resource Manager templates are available for download and deployment.

若要检查最新模板,请访问 Azure 快速启动模板库并搜索“服务总线” 。To check for the latest templates, visit the Azure Quickstart Templates gallery and search for Service Bus.

要部署什么?What do you deploy?

使用此模板,将部署包含主题和订阅的服务总线命名空间。With this template, you deploy a Service Bus namespace with topic and subscription.

服务总线主题和订阅以“发布/订阅”模式提供一对多的通信形式。Service Bus topics and subscriptions provide a one-to-many form of communication, in a publish/subscribe pattern.

若要自动运行部署,请单击以下按钮:To run the deployment automatically, click the following button:

部署到 AzureDeploy to Azure

parametersParameters

使用 Azure 资源管理器,可以定义在部署模板时想要指定的值的参数。With Azure Resource Manager, you define parameters for values you want to specify when the template is deployed. 该模板具有一个名为 Parameters 的部分,其中包含所有参数值。The template includes a section called Parameters that contains all of the parameter values. 为随着要部署的项目或要部署到的环境而变化的值定义参数。Define a parameter for those values that vary based on the project you're deploying or based on the environment you're deploying to. 不要为永远保持不变的值定义参数。Do not define parameters for values that always stay the same. 每个参数值可在模板中用来定义所部署的资源。Each parameter value is used in the template to define the resources that are deployed.

模板定义以下参数:The template defines the following parameters:

serviceBusNamespaceNameserviceBusNamespaceName

要创建的服务总线命名空间的名称。The name of the Service Bus namespace to create.

"serviceBusNamespaceName": {
"type": "string"
}

serviceBusTopicNameserviceBusTopicName

在服务总线命名空间中创建的主题的名称。The name of the topic created in the Service Bus namespace.

"serviceBusTopicName": {
"type": "string"
}

serviceBusSubscriptionNameserviceBusSubscriptionName

在服务总线命名空间中创建的订阅的名称。The name of the subscription created in the Service Bus namespace.

"serviceBusSubscriptionName": {
"type": "string"
}

serviceBusApiVersionserviceBusApiVersion

模板的服务总线 API 版本。The Service Bus API version of the template.

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

要部署的资源Resources to deploy

创建类型为 Messaging的包含主题和订阅的标准服务总线命名空间。Creates a standard Service Bus namespace of type Messaging, with topic and subscription.

"resources ": [{
        "apiVersion": "[variables('sbVersion')]",
        "name": "[parameters('serviceBusNamespaceName')]",
        "type": "Microsoft.ServiceBus/Namespaces",
        "location": "[variables('location')]",
        "kind": "Messaging",
        "sku": {
            "name": "Standard",
        },
        "resources": [{
            "apiVersion": "[variables('sbVersion')]",
            "name": "[parameters('serviceBusTopicName')]",
            "type": "Topics",
            "dependsOn": [
                "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespaceName'))]"
            ],
            "properties": {
                "path": "[parameters('serviceBusTopicName')]",
            },
            "resources": [{
                "apiVersion": "[variables('sbVersion')]",
                "name": "[parameters('serviceBusSubscriptionName')]",
                "type": "Subscriptions",
                "dependsOn": [
                    "[parameters('serviceBusTopicName')]"
                ],
                "properties": {}
            }]
        }]
    }]

运行部署的命令Commands to run deployment

要将资源部署到 Azure,必须登录到 Azure 帐户,并且必须使用 Azure 资源管理器模块。To deploy the resources to Azure, you must be signed in to your Azure account and you must use the Azure Resource Manager module. 若要了解配合使用 Azure Resource Manager 和 Azure PowerShell 或 Azure CLI 的相关信息,请参阅:To learn about using Azure Resource Manager with either Azure PowerShell or Azure CLI, see:

以下示例假定帐户中已具有一个指定名称的资源组。The following examples assume you already have a resource group in your account with the specified name.

PowerShellPowerShell

New-AzureResourceGroupDeployment -Name \<deployment-name\> -ResourceGroupName \<resource-group-name\> -TemplateUri <https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-servicebus-create-topic-and-subscription/azuredeploy.json>

Azure CLIAzure CLI

azure config mode arm

azure group deployment create \<my-resource-group\> \<my-deployment-name\> --template-uri <https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-servicebus-create-topic-and-subscription/azuredeploy.json>

后续步骤Next steps

现在,已使用 Azure 资源管理器创建并部署了资源,请通过查看以下文章了解如何管理这些资源:Now that you've created and deployed resources using Azure Resource Manager, learn how to manage these resources by viewing these articles: