AzureServiceBusLogo_150An Microsoft Azure Service Bus Namespace can certainly be managed through the Azure Management Portal. However easy that is for a user to do manually, it definitely can be useful to create and manage Azure Service Bus Namespaces using other more automated methods. Fortunately, there is support for this using the PowerShell and X-plat CLI SDKs.

Below are examples using both the PowerShell and X-plat CLI (command-line) SDKs to create a new Azure Service Bus Namespace.

Azure PowerShell cmdlets

Creating an Azure Service Bus Namespace with the Azure PowerShell SDK is fairly simple using the New-AzureSBNamespace cmdlet.

Explicitly define parameters:

[code language=”powershell”]

New-AzureSBNamespace -name SuperNamespace -Location North Central US

[/code]

Implicitly define parameters:

[code language=”powershell”]

New-AzureSBNamespace SuperNamespace ‘North Central US’

[/code]

Before you run the New-AzureSBNamespace cmdlet to create the Azure Service Bus Namespace, you need to import the Azure cmdlets and login to your Azure subscription. Here’s a short, full example of doing this:

[code language=”powershell”]

# import Azure cmdlets
Import-Module Azure

# Login to Azure
Add-AzureAccount

# Create Namespace on the Azure Subscription that was logged into
New-AzureSBNamespace SuperNamespace "North Central US"

[/code]

Note: The Add-AzureAccount cmdlet will open up a window for the user to enter their Microsoft Account credentials to login to the Azure Subscription.

Azure CLI 1.0

The biggest benefit of the X-plat CLI is that is runs on Mac OS and Linux. Since PowerShell doesn’t run on non-Windows operating system, this is extremely useful for anyone using Microsoft Azure without Windows.

Creating an Azure Service Bus Namespace can be done using the X-plat CLI using the following command.

[code]

azure sb namespace create <namespace> <region>

[/code]

Before you can create the Azure Service Bus Namespace, you’ll need to login to your Azure subscription. Below is a short example that includes this:

[code]

#log into Azure account
azure login -u <username>

# create Azure Service Bus Namespace
azure sb namespace create <namespace> <region>

[/code]

Note: The “azure login” command specifies the username to login with, but it then prompts the user to enter the password.

PowerShell vs Xplat-CLI

Both the PowerShell SDK and the Xplat-CLI SDK contain the same features. The Azure team does a good job at keeping both of these SDK’s in good parity. They both contain a huge amount of functionality for automating Azure resource management.

Additionally, both SDKs are Open Source and hosted on GitHub.

Posted by Chris Pietschmann

Chris is a Microsoft MVP and has 15+ years of experience building enterprise systems both in the cloud and on-premises. He is also a Microsoft Certified (MCSD) Azure Solutions Architect. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.

3 Comments

  1. […] Create Azure Service Bus Namespaces using PowerShell and X-plat CLI […]

    Reply

  2. […] Azure Service Bus Namespace must first be created before a Service Bus Queue can be created and managed. Once the Service Bus Namespace has been […]

    Reply

  3. […] For proof, here’s the Azure PowerShell cmdlet for creating an Azure Service Bus Namespace: […]

    Reply

Leave a Reply