Quickstart: Create an event hub using Azure PowerShell

In this quickstart, you create an event hub using Azure PowerShell.

Prerequisites

An Azure account with an active subscription. Create a trial subscription.

Note

Before you can use Azure CLI in Microsoft Azure operated by 21Vianet, please run az cloud set -n AzureChinaCloud first to change the cloud environment. If you want to switch back to Azure Public Cloud, run az cloud set -n AzureCloud again.

If you're using PowerShell locally, you must run the latest version of PowerShell to complete this quickstart. If you need to install or upgrade, see Install and Configure Azure PowerShell.

Create a resource group

Run the following command to create a resource group. A resource group is a logical collection of Azure resources. All resources are deployed and managed in a resource group.

If you're using Azure local Shell, switch to PowerShell from Bash in the upper left corner. Select Copy to copy the command and paste it into the local Shell, and run it.

The following example creates a resource group in the China East region. Replace myResourceGroup with the name of the resource group you want to use.

$rgName="myResourceGroup$(Get-Random)"
$region="chinaeast"
New-AzResourceGroup -Name $rgName -Location $region

Create an Event Hubs namespace

Run the following command to create an Event Hubs namespace in the resource group. An Event Hubs namespace provides a unique fully qualified domain name in which you can create one or more event hubs. Update the value of the namespace if you like.

$namespaceName="myNamespace$(Get-Random)"
New-AzEventHubNamespace -ResourceGroupName $rgName -NamespaceName $namespaceName -Location $region

Create an event hub

Now that you have an Event Hubs namespace, create an event hub within that namespace by running the following command.

$ehubName="myEventHub"
New-AzEventHub -ResourceGroupName $rgName -NamespaceName $namespaceName -EventHubName $ehubName

Congratulations! You have used Azure PowerShell to create an Event Hubs namespace, and an event hub within that namespace.

Clean up resources

If you want to keep this event hub so that you can test sending and receiving events, ignore this section. Otherwise, run the following command to delete the resource group. This command deletes all the resources in the resource group and the resource group itself.

Remove-AzResourceGroup $rgName

Next steps

In this article, you created the Event Hubs namespace, and used sample applications to send and receive events from your event hub. For step-by-step instructions to send events to (or) receive events from an event hub, see the Send and receive events tutorials: