Create a Service Bus namespace by using an Azure Resource Manager template
Learn how to deploy an Azure Resource Manager template to create a Service Bus namespace. You can use this template for your own deployments, or customize it to meet your requirements. For more information about creating templates, see Azure Resource Manager documentation.
The following templates are also available for creating Service Bus namespaces:
- Create a Service Bus namespace with queue
- Create a Service Bus namespace with topic and subscription
- Create a Service Bus namespace with queue and authorization rule
- Create a Service Bus namespace with topic, subscription, and rule
Note
We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
If you don't have an Azure subscription, create a free account before you begin.
Create a service bus namespace
In this quickstart, you use an existing Resource Manager template from Azure Quickstart Templates:
{
"$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": {}
}
]
}
To find more template samples, see Azure Quickstart Templates.
To create a service bus namespace by deploying a template:
Select Try it from the following code block, and then follow the instructions to sign in to the 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 ..."
The resource group name is the service bus namespace name with rg appended.
Select Copy to copy the PowerShell script.
Right-click the shell console, and then select Paste.
It takes a few moments to create an event hub.
Verify the deployment
To see the deployed service bus namespace, you can either open the resource group from the Azure portal, or use the following Azure PowerShell script. If the Cloud shell is still open, you don't need to copy/run the first and second lines of the following script.
$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 is used to deploy the template in this tutorial. For other template deployment methods, see:
Clean up resources
When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group. If the Cloud shell is still open, you don't need to copy/run the first and second lines of the following script.
$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 ..."
Next steps
In this article, you created a Service Bus namespace. See the other quickstarts to learn how to create queues, topics/subscriptions, and use them: