使用 Azure 资源管理器模板创建服务总线命名空间

了解如何部署 Azure 资源管理器模板以创建服务总线命名空间。 可将此模板用于自己的部署,或自定义此模板以满足要求。 有关创建模板的详细信息,请参阅 Azure 资源管理器文档

还可使用以下模板创建服务总线命名空间:

注意

建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az

如果没有 Azure 订阅,请在开始前创建试用版订阅

创建服务总线命名空间

在本快速入门中,使用 Azure 快速启动模板中的现有资源管理器模板

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "serviceBusNamespaceName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Service Bus namespace"
      }
    },
    "serviceBusSku": {
      "type": "string",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ],
      "defaultValue": "Standard",
      "metadata": {
        "description": "The messaging tier for service Bus namespace"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2018-01-01-preview",
      "name": "[parameters('serviceBusNamespaceName')]",
      "type": "Microsoft.ServiceBus/namespaces",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('serviceBusSku')]"
      },
      "properties": {}
    }
  ]
}

若要查找更多模板示例,请参阅 Azure 快速入门模板

若要通过部署模板创建服务总线命名空间,请执行以下操作:

  1. 在本地计算机上使用 PowerShell 登录到由世纪互联运营的 Azure。

    $serviceBusNamespaceName = Read-Host -Prompt "Enter a name for the service bus namespace to be created"
    $location = Read-Host -Prompt "Enter the location (i.e. chinanorth)"
    $resourceGroupName = "${serviceBusNamespaceName}rg"
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.servicebus/servicebus-create-namespace/azuredeploy.json"
    
    New-AzResourceGroup -Name $resourceGroupName -Location $location
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -serviceBusNamespaceName $serviceBusNamespaceName
    
    Write-Host "Press [ENTER] to continue ..."
    

    资源组名称是追加了 rg 的服务总线命名空间名称。

  2. 选择“复制”以复制 PowerShell 脚本。

  3. 右键单击 shell 控制台并选择“粘贴” 。

创建事件中心需要花费片刻时间。

验证部署

若要查看部署的服务总线命名空间,可以从 Azure 门户打开资源组,或者使用以下 Azure PowerShell 脚本。 如果 PowerShell 控制台仍处于打开状态,则无需复制/运行以下脚本的第一行和第二行。

$serviceBusNamespaceName = Read-Host -Prompt "Enter the same service bus namespace name used earlier"
$resourceGroupName = "${serviceBusNamespaceName}rg"

Get-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $serviceBusNamespaceName

Write-Host "Press [ENTER] to continue ..."

在本教程中,请使用 Azure PowerShell 来部署模板。 如需其他模板部署方法,请参阅:

清理资源

不再需要 Azure 资源时,请通过删除资源组来清理部署的资源。 如果 PowerShell 控制台仍处于打开状态,则无需复制/运行以下脚本的第一行和第二行。

$serviceBusNamespaceName = Read-Host -Prompt "Enter the same service bus namespace name used earlier"
$resourceGroupName = "${serviceBusNamespaceName}rg"

Remove-AzResourceGroup -ResourceGroupName $resourceGroupName

Write-Host "Press [ENTER] to continue ..."

后续步骤

在本文中,我们已创建一个服务总线命名空间。 请参阅其他快速入门,了解如何创建和使用队列、主题/订阅: