使用 Azure Resource Manager 範本來建立服務匯流排命名空間

了解如何部署 Azure Resource Manager 範本來建立服務匯流排命名空間。 您可以直接在自己的部署中使用此範本,或自訂此範本以符合您的需求。 如需關於建立範本的詳細資訊,請參閱 Azure Resource Manager 文件

下列範本也可用於建立服務匯流排命名空間:

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

如尚未擁有 Azure 訂用帳戶,請在開始之前先建立免費帳戶

建立服務匯流排命名空間

在本快速入門中,您可以從 Azure 快速入門範本使用現有的 Resource Manager 範本

{
  "$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. 選取下列程式碼區塊中的 [試用],然後依照指示登入 Azure Cloud Shell。

    $serviceBusNamespaceName = Read-Host -Prompt "Enter a name for the service bus namespace to be created"
    $location = Read-Host -Prompt "Enter the location (i.e. centralus)"
    $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. 以滑鼠右鍵按一下殼層主控台,然後選取 [貼上]

建立事件中樞需要幾分鐘的時間。

檢查部署

若要查看部署的服務匯流排命名空間,您可以從 Azure 入口網站中開啟資源群組,或使用下列 Azure PowerShell 指令碼。 如果 Cloud Shell 仍然開啟,您就不需要複製/執行下列指令碼的第一行和第二行。

$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 資源時,可藉由刪除資源群組來清除您所部署的資源。 如果 Cloud Shell 仍然開啟,您就不需要複製/執行下列指令碼的第一行和第二行。

$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 ..."

下一步

在本文中,您已建立「服務匯流排」命名空間。 請參閱其他快速入門以了解如何建立佇列、主題/訂用帳戶,以及如何使用它們: