Azure Service Bus is a fully managed cloud messaging service in Microsoft Azure that acts as a reliable intermediary between applications and services. Think of it as a post office in the cloud, senders drop off messages, and receivers pick them up when ready, with no need for both parties to be online at the same time.
It supports two core messaging patterns: queues (point-to-point, one sender → one receiver) and topics/subscriptions (publish-subscribe, one sender → multiple receivers). Messages are stored durably until processed, making it ideal for decoupling distributed systems.
Real-world examples
E-commerce order processing
When a customer places an order, the Order Service drops a message into a queue. The Payment Service picks it up independently. If payment processing is slow or briefly down, orders aren't lost they wait in the queue.Inventory updates (pub-sub)
When stock changes, the Inventory Service publishes a message to a topic. Three separate subscribers receive it simultaneously: a Warehouse app (to pick items), an Analytics service (to update dashboards), and an Email service (to notify customers). None of them needs to know about each other.Microservices decoupling
In a large banking app, the Loan Service sends an approval message to the Service Bus. Downstream services like Document Generation, Notifications, and Auditing each consume that event independently — if one crashes, the others keep running.
Configuration Example
Let's make the configuration using:
- Terraform # variables.tf variable "resource_group_name" { description = "Your existing RG name" type = string }
variable "location" {
description = "Azure region"
type = string
default = "eastus"
}
variable "namespace_name" {
description = "Service Bus namespace name (globally unique)"
type = string
}
main.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
}
provider "azurerm" {
features {}
}
Reference your EXISTING resource group (don't create a new one)
data "azurerm_resource_group" "existing" {
name = var.resource_group_name
}
Service Bus Namespace
resource "azurerm_servicebus_namespace" "sb_namespace" {
name = var.namespace_name
location = data.azurerm_resource_group.existing.location
resource_group_name = data.azurerm_resource_group.existing.name
sku = "Standard" # Standard tier required for Topics
tags = {
environment = "lab"
source = "terraform"
}
}
Topic
resource "azurerm_servicebus_topic" "sb_topic" {
name = "lab-topic"
namespace_id = azurerm_servicebus_namespace.sb_namespace.id
enable_partitioning = true
}
Subscription
resource "azurerm_servicebus_subscription" "sb_subscription" {
name = "lab-subscription"
topic_id = azurerm_servicebus_topic.sb_topic.id
max_delivery_count = 10
}
terraform.tfvars
resource_group_name = "your-existing-rg-name"
namespace_name = "sb-whizlab-namespace" # must be globally unique
Deploy:
terraform init
terraform plan
terraform apply
- Azure PowerShell ── Variables ────────────────────────────────────────────────── $ResourceGroupName = "your-existing-rg-name" # Your existing RG $NamespaceName = "sb-whizlab-namespace" # Globally unique $TopicName = "lab-topic" $SubscriptionName = "lab-subscription"
── Login (skip if already authenticated) ──────────────────────
Connect-AzAccount
── Get existing RG to inherit location ────────────────────────
$rg = Get-AzResourceGroup -Name $ResourceGroupName
$Location = $rg.Location
── Create Service Bus Namespace ───────────────────────────────
New-AzServiceBusNamespace
-ResourceGroupName $ResourceGroupName
-Name $NamespaceName
-Location $Location
-SkuName "Standard"
── Create Topic ───────────────────────────────────────────────
New-AzServiceBusTopic
-ResourceGroupName $ResourceGroupName
-NamespaceName $NamespaceName
-Name $TopicName
-EnablePartitioning $true
── Create Subscription ────────────────────────────────────────
New-AzServiceBusSubscription
-ResourceGroupName $ResourceGroupName
-NamespaceName $NamespaceName
-TopicName $TopicName
-Name $SubscriptionName `
-MaxDeliveryCount 10
── Verify ─────────────────────────────────────────────────────
Write-Host "`n✅ Resources created:" -ForegroundColor Green
Get-AzServiceBusNamespace -ResourceGroupName $ResourceGroupName -Name $NamespaceName |
Select-Object Name, Location, Sku, ProvisioningState



Top comments (0)