Azure Resource Manager テンプレートを使用した Service Bus 名前空間の作成

Azure Resource Manager テンプレートをデプロイして Service Bus 名前空間を作成する方法について説明します。 このテンプレートは、独自のデプロイに使用することも、要件に合わせてカスタマイズすることもできます。 テンプレートの作成の詳細については、「Azure Resource Manager のドキュメント」をご覧ください。

Service Bus 名前空間を作成するために、次のテンプレートも使用できます。

Note

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、Azure PowerShell のインストールに関する記事を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

Azure サブスクリプションをお持ちでない場合は、開始する前に無料アカウントを作成してください。

Service Bus 名前空間の作成を作成する

このクイック スタートでは、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 クイック スタート テンプレート」をご覧ください。

テンプレートをデプロイして Service Bus 名前空間を作成するには:

  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 が追加された Service Bus 名前空間名です。

  2. [コピー] を選択し、PowerShell スクリプトがコピーされます。

  3. シェル コンソールを右クリックし、 [貼り付け] を選択します。

イベント ハブが作成されるまでしばらく時間がかかります。

デプロイを検証する

デプロイされた Service Bus 名前空間を確認するには、Azure portal からリソース グループを開くか、次の Azure PowerShell スクリプトを使用します。 Cloud Shell がまだ開いている場合は、次のスクリプトの 1 番目と 2 番目の行をコピー/実行する必要はありません。

$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 がまだ開いている場合は、次のスクリプトの 1 番目と 2 番目の行をコピー/実行する必要はありません。

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

次のステップ

この記事では、Service Bus 名前空間を作成しました。 キュー、トピック/サブスクリプションを作成して使用する方法については、他のクイック スタートを参照してください。