| title | Quickstart - Use the Azure CLI to create a Service Bus queue | Microsoft Docs | |||
|---|---|---|---|---|
| description | In this quickstart, you learn how to use the Azure CLI to create a Service Bus namespace and then a queue in that namespace. | |||
| author | spelluru | |||
| ms.topic | quickstart | |||
| ms.date | 01/24/2024 | |||
| ms.author | spelluru | |||
| ms.devlang | azurecli | |||
| ms.custom |
|
This quickstart shows you how to create a Service Bus namespace and a queue using the Azure CLI. It also shows you how to get authorization credentials that a client application can use to send/receive messages to/from the queue.
[!INCLUDE service-bus-queues]
If you don't have an Azure subscription, you can create a free account before you begin.
In this quickstart, you use Azure Cloud Shell that you can launch after signing in to the Azure portal. For details about Azure Cloud Shell, see Overview of Azure Cloud Shell. You can also install and use Azure PowerShell on your machine.
-
Sign in to the Azure portal.
-
Launch Azure Cloud Shell by selecting the icon shown in the following image. Switch to Bash mode if the Cloud Shell is in PowerShell mode.
:::image type="icon" source="~/reusable-content/ce-skilling/azure/media/cloud-shell/launch-cloud-shell-button.png" alt-text="Button to launch the Azure Cloud Shell." border="false" link="https://shell.azure.com":::
-
Run the following command to create an Azure resource group. Update the resource group name and the location if you want.
az group create --name ContosoRG --location eastus -
Run the following command to create a Service Bus messaging namespace.
az servicebus namespace create --resource-group ContosoRG --name ContosoSBusNS --location eastus -
Run the following command to create a queue in the namespace you created in the previous step. In this example,
ContosoRGis the resource group you created in the previous step.ContosoSBusNSis the name of the Service Bus namespace created in that resource group.az servicebus queue create --resource-group ContosoRG --namespace-name ContosoSBusNS --name ContosoOrdersQueue -
Run the following command to get the primary connection string for the namespace. You use this connection string to connect to the queue and send and receive messages.
az servicebus namespace authorization-rule keys list --resource-group ContosoRG --namespace-name ContosoSBusNS --name RootManageSharedAccessKey --query primaryConnectionString --output tsvNote down the connection string and the queue name. You use them to send and receive messages.
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.