Deploy Service Bus and its entities with ARM
  • 24 Jun 2022
  • 1 Minute to read
  • Contributors
  • Comments
  • Dark
    Light
  • PDF

Deploy Service Bus and its entities with ARM

  • Comments
  • Dark
    Light
  • PDF

#ServerlessTips - Azure Service Bus
Author: Steef-Jan Wiggers Azure MVP

With Azure Resource Manager (ARM) templates you can deploy Azure resources. One of the resources you can deploy is a service bus namespace with entities such as queue and topic. You author an ARM template using JSON format and create expression to construct values for your deployment of a service namespace. The ARM template below shows the JSON for creating a service bus namespace.

{
"$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."
}
}
},
"variables": {
"defaultSASKeyName": "RootManageSharedAccessKey",
"defaultAuthRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('serviceBusNamespaceName'), variables('defaultSASKeyName'))]",
"sbVersion": "2017-04-01"
},
"resources": [
{
"apiVersion": "2017-04-01",
"name": "[parameters('serviceBusNamespaceName')]",
"type": "Microsoft.ServiceBus/namespaces",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('serviceBusSku')]"
}
}
],
"outputs": {
"NamespaceDefaultConnectionString": {
"type": "string",
"value": "[listkeys(variables('defaultAuthRuleResourceId'), variables('sbVersion')).primaryConnectionString]"
},
"DefaultSharedAccessPolicyPrimaryKey": {
"type": "string",
"value": "[listkeys(variables('defaultAuthRuleResourceId'), variables('sbVersion')).primaryKey]"
}
}
}

You can apply the template by using PowerShell script in the Cloud Shell. Or you use the Azure Portal using a custom template, CLI, or REST API. Either way it is good practice to deploy resources such as a Service Bus Namespace using ARM templates to keep it consist over various environments (Development, UAT, and production).

Beside deploying just a Service Bus Namespace you could include creation of queues, topics, authorization rule, and subscriptions. The Microsoft Docs provide examples of those ARM templates.

Also, get insights into Azure Service Bus monitoring on messaging issues and how you can improve them.

Service Bus-2


Was this article helpful?