Use Azure PowerShell to create a Service Bus namespace and a queue
This quickstart shows you how to create a Service Bus namespace and a queue using the Azure PowerShell. It also shows you how to get authorization credentials that a client application can use to send/receive messages to/from the queue.
What are Service Bus queues?
Service Bus queues support a brokered messaging communication model. When you use queues, components of a distributed application don't communicate directly with each other; instead they exchange messages via a queue, which acts as an intermediary (broker). A message producer (sender) hands off a message to the queue and then continues its processing. Asynchronously, a message consumer (receiver) pulls the message from the queue and processes it. The producer doesn't have to wait for a reply from the consumer in order to continue to process and send further messages. Queues offer First In, First Out (FIFO) message delivery to one or more competing consumers. That is, messages are typically received and processed by the receivers in the order in which they were added to the queue, and each message is received and processed by only one message consumer.
Service Bus queues are a general-purpose technology that can be used for a wide variety of scenarios:
- Communication between web and worker roles in a multi-tier Azure application.
- Communication between on-premises apps and Azure-hosted apps in a hybrid solution.
- Communication between components of a distributed application running on-premises in different organizations or departments of an organization.
Using queues enables you to scale your applications more easily, and enable more resiliency to your architecture.
Prerequisites
To complete this quickstart, make sure you have an Azure subscription. If you don't have an Azure subscription, you can create a trial subscription before you begin.
You can install and use Azure PowerShell on your machine.
Provision resources
First, install the Service Bus PowerShell module, if you haven't already:
Install-Module Az.ServiceBus
Run the following command to sign in to Azure:
Connect-AzAccount -Environment AzureChinaCloud
Invoke the following commands to set the current subscription context, or to see the currently active subscription:
Select-AzSubscription -SubscriptionName "MyAzureSubName" Get-AzContext
Run the following command to create an Azure resource group. Update the resource group name and the location if you want.
New-AzResourceGroup -Name ContosoRG -Location chinaeast
Run the following command to create a Service Bus messaging namespace. In this example,
ContosoRG
is the resource group you created in the previous step.ContosoSBusNS
is the name of the Service Bus namespace created in that resource group.New-AzServiceBusNamespace -ResourceGroupName ContosoRG -Name ContosoSBusNS -Location chinaeast
Run the following to create a queue in the namespace you created in the previous step.
New-AzServiceBusQueue -ResourceGroupName ContosoRG -NamespaceName ContosoSBusNS -Name ContosoOrdersQueue
Get the primary connection string for the namespace. You use this connection string to connect to the queue and send and receive messages.
Get-AzServiceBusKey -ResourceGroupName ContosoRG -Namespace ContosoSBusNS -Name RootManageSharedAccessKey
Note down the connection string and the queue name. You use them to send and receive messages.
Next steps
In this article, you created a Service Bus namespace and a queue in the namespace. To learn how to send/receive messages to/from the queue, see one of the following quickstarts in the Send and receive messages section.