Sitecore 10: Creating Azure Service Bus Queues & Topics

Recently, during an audit of a client’s azure footprint for a Sitecore XP implementation, I discovered that two of our four environments were using a Premium tier of Azure Service Bus while the other two were using the Standard Tier. The Premium Tier is SIGNIFICANTLY more expensive – ~$700/month vs ~$20/month! When we went to downgrade these premium tier services, we found that we couldn’t. We even contacted Microsoft and they confirmed that, once you create or migrate to a Premium Tier ASB, there is no path back to Standard Tier. So, our only option was to create two new Azure Service Bus services and delete the old ones.

Overall, this is a pretty simple process. Once the new ASB services were provisioned and available, it was easy enough to just update Key Vault with the new connection string for the messaging¬†and redeploy the environment. Once everything was back up, I assumed that Sitecore would create whatever queues and topics it needed on demand, if they didn’t already exist. This, however, was a very incorrect assumption. They needed to be created manually.

Powershell to the Rescue

Since there are 17 queues and 2 topics that need to be created in each of the two new ASBs, clicking through the UI to create everything just ain’t gonna fly! Below is the script I wrote to create the queues and topics. If you don’t already have the Az.ServiceBus¬†powershell module installed, you’ll need to Install-Module -name Az.ServiceBus.

$subscriptionId = "<ID of the subscription hosting the ASB>"
$resourceGroup = "<Name of the Resource Group hosting the ASB>"

function create-queue {
    param (
        [string] $name,
        [string] $namespace
    )

    New-AzServiceBusQueue -Name $name -NamespaceName $namespace -ResourceGroupName $resourceGroup -SubscriptionId $subscriptionId -DefaultMessageTimeToLive (New-TimeSpan -Days 10000) -LockDuration (New-TimeSpan -Minutes 5) -MaxDeliveryCount 10 -MaxSizeInMegabytes 1024
}

function create-topic {
    param (
        [string] $name,
        [string] $namespace
    )

    New-AzServiceBusTopic -Name $name -NamespaceName $namespace -ResourceGroupName $resourceGroup -SubscriptionId $subscriptionId -SupportOrdering:$false
}

$serviceBus = "<name of the Azure Service Bus>"

create-queue -name "error" -namespace $serviceBus
create-queue -name "sitecore_ct_modeltrainingtaskstatussubscriber" -namespace $serviceBus
create-queue -name "sitecore_exm_automatedmessagesqueue" -namespace $serviceBus
create-queue -name "sitecore_exm_clearsuppressionlistqueue" -namespace $serviceBus
create-queue -name "sitecore_exm_confirmsubscriptionmessagesqueue" -namespace $serviceBus
create-queue -name "sitecore_exm_emailaddresshistorymessagesqueue" -namespace $serviceBus
create-queue -name "sitecore_exm_emailopenedmessagesqueue" -namespace $serviceBus
create-queue -name "sitecore_exm_sentmessagesqueue" -namespace $serviceBus
create-queue -name "sitecore_exm_updatelistsubscriptionmessagesqueue" -namespace $serviceBus
create-queue -name "sitecore_ma_purgefromcampaignmessages" -namespace $serviceBus
create-queue -name "sitecore_pe_taskcancellationconsumer" -namespace $serviceBus
create-queue -name "sitecore_pe_taskcancellationproducer" -namespace $serviceBus
create-queue -name "sitecore_pe_taskprogressconsumer" -namespace $serviceBus
create-queue -name "sitecore_pe_taskprogressproducer" -namespace $serviceBus
create-queue -name "sitecore_pe_taskregistrationconsumer" -namespace $serviceBus
create-queue -name "sitecore_pe_taskregistrationproducer" -namespace $serviceBus
create-queue -name "sitecore_pe_taskstatuspublisher" -namespace $serviceBus

create-topic -name "sitecore.processing.engine.abstractions~sitecore.processing.engine.abstractions.messages.taskstatus" -namespace $serviceBus
create-topic -name "sitecore_processing_engine_abstractions_messages_taskstatus__sitecore_processing_engine_abstractions" -namespace $serviceBus

write-host "script complete"

Hopefully this helps!

Happy Sitecore trails, my friend!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: