快速入門:使用 Azure Resource Manager 範本建立服務匯流排命名空間與主題和訂用帳戶Quickstart: 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 Resource Manager 範本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.

注意

下列 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

參數Parameters

透過 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

建立 訊息 類型的標準服務匯流排命名空間與主題和訂用帳戶。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": {}
            }]
        }]
    }]

若要了解 JSON 語法和屬性,請參閱命名空間主題訂用帳戶For JSON syntax and properties, see namespaces, topics, and subscriptions.

執行部署的命令Commands to run deployment

若要將資源部署至 Azure,您必須登入 Azure 帳戶,而且必須使用 Azure Resource Manager 模組。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 資源管理員與 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

az deployment group create \<my-resource-group\> --name \<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 Resource Manager 建立並部署資源,請檢視這些文件,了解如何管理這些資源︰Now that you've created and deployed resources using Azure Resource Manager, learn how to manage these resources by viewing these articles: