Azure Resource Manager テンプレートをデプロイして Service Bus 名前空間を作成する方法について説明します。 このテンプレートは、独自のデプロイに使用することも、要件に合わせてカスタマイズすることもできます。 テンプレートの作成の詳細については、 Azure Resource Manager のドキュメントを参照してください。
Service Bus 名前空間の作成には、次のテンプレートも使用できます。
- キューを使用して Service Bus 名前空間を作成する
- トピックとサブスクリプションを使用して Service Bus 名前空間を作成する
- キューと承認規則を使用して Service Bus 名前空間を作成する
- トピック、サブスクリプション、ルールを使用して Service Bus 名前空間を作成する
注
Azure Az PowerShell モジュールを使用して Azure と対話することをお勧めします。 作業を始めるには、「Azure PowerShell をインストールする」を参照してください。 Az PowerShell モジュールに移行する方法については、「 Azure PowerShell を AzureRM から Az に移行する」を参照してください。
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 名前空間を作成するには:
次のコード ブロックから [ 試してみる ] を選択し、指示に従って 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 名前空間名です。
[ コピー] を選択して PowerShell スクリプトをコピーします。
シェル コンソールを右クリックし、[ 貼り付け] を選択します。
イベント ハブの作成には少し時間がかかります。
デプロイメントを確認する
デプロイされた 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 名前空間を作成しました。 キュー、トピック/サブスクリプションを作成し、それらを使用する方法については、他のクイック スタートを参照してください。