|
2 | 2 | title: 'Quickstart: Create an event hub using PowerShell'
|
3 | 3 | description: This quickstart describes how to create an event hub using Azure PowerShell and then send and receive events using .NET Standard SDK.
|
4 | 4 | ms.topic: quickstart
|
5 |
| -ms.date: 09/28/2021 |
| 5 | +ms.date: 03/13/2023 |
6 | 6 | ms.custom: devx-track-azurepowershell, mode-api
|
7 | 7 | ---
|
8 | 8 |
|
9 | 9 | # Quickstart: Create an event hub using Azure PowerShell
|
10 |
| -In this quickstart, you will create an event hub using Azure PowerShell. |
| 10 | +In this quickstart, you create an event hub using Azure PowerShell. |
11 | 11 |
|
12 | 12 | ## Prerequisites
|
13 | 13 | An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
|
14 | 14 |
|
15 |
| -[!INCLUDE [azure-powershell-prepare-your-environment.md](~/articles/reusable-content/azure-powershell/azure-powershell-prepare-your-environment.md)] |
16 |
| - |
17 |
| - |
18 | 15 | [!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
|
19 | 16 |
|
20 | 17 | 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](/powershell/azure/install-az-ps).
|
21 | 18 |
|
22 | 19 | ## Create a resource group
|
| 20 | +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. |
23 | 21 |
|
24 |
| -A resource group is a logical collection of Azure resources, and you need a resource group to create an event hub. |
| 22 | +If you're using Azure Cloud Shell, switch to **PowerShell** from **Bash** in the upper left corner. Select **Copy** to copy the command and paste it into the Cloud Shell, and run it. |
25 | 23 |
|
26 |
| -The following example creates a resource group in the East US region. Replace `myResourceGroup` with the name of the resource group you want to use: |
| 24 | +The following example creates a resource group in the East US region. Replace `myResourceGroup` with the name of the resource group you want to use. |
27 | 25 |
|
28 | 26 | ```azurepowershell-interactive
|
29 |
| -New-AzResourceGroup –Name myResourceGroup –Location eastus |
| 27 | +$rgName="myResourceGroup$(Get-Random)" |
| 28 | +$region="eastus" |
| 29 | +New-AzResourceGroup –Name $rgName –Location $region |
| 30 | +``` |
| 31 | +You see the output similar to the following one. You see the name of the resource with the random number suffix. |
| 32 | + |
| 33 | +```bash |
| 34 | +ResourceGroupName : myResourceGroup1625872532 |
| 35 | +Location : eastus |
| 36 | +ProvisioningState : Succeeded |
| 37 | +Tags : |
| 38 | +ResourceId : /subscriptions/0000000000-0000-0000-0000-0000000000000/resourceGroups/myResourceGroup1625872532 |
30 | 39 | ```
|
31 | 40 |
|
32 | 41 | ## Create an Event Hubs namespace
|
33 |
| - |
34 |
| -Once your resource group is made, create an Event Hubs namespace within that resource group. An Event Hubs namespace provides a unique fully-qualified domain name in which you can create your event hub. Replace `namespace_name` with a unique name for your namespace: |
| 42 | +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. |
35 | 43 |
|
36 | 44 | ```azurepowershell-interactive
|
37 |
| -New-AzEventHubNamespace -ResourceGroupName myResourceGroup -NamespaceName namespace_name -Location eastus |
| 45 | +$namespaceName="myNamespace$(Get-Random)" |
| 46 | +New-AzEventHubNamespace -ResourceGroupName $rgName -NamespaceName $namespaceName -Location $region |
| 47 | +``` |
| 48 | + |
| 49 | +You see the output similar to the following one. You see the name of the namespace in the `Name` field. |
| 50 | + |
| 51 | +```bash |
| 52 | +Name : myNamespace143349827 |
| 53 | +Id : /subscriptions/0000000000-0000-0000-0000-00000000000000/resourceGroups/myResourceGroup162587253 |
| 54 | + 2/providers/Microsoft.EventHub/namespaces/myNamespace143349827 |
| 55 | +ResourceGroupName : myResourceGroup1625872532 |
| 56 | +Location : East US |
| 57 | +Sku : Name : Standard , Capacity : 1 , Tier : Standard |
| 58 | +Tags : |
| 59 | +ProvisioningState : Succeeded |
| 60 | +Status : Active |
| 61 | +CreatedAt : 3/13/2023 10:22:54 PM |
| 62 | +UpdatedAt : 3/13/2023 10:23:41 PM |
| 63 | +ServiceBusEndpoint : https://myNamespace143349827.servicebus.windows.net:443/ |
| 64 | +Enabled : True |
| 65 | +KafkaEnabled : True |
| 66 | +IsAutoInflateEnabled : False |
| 67 | +MaximumThroughputUnits : 0 |
| 68 | +ZoneRedundant : False |
| 69 | +ClusterArmId : |
| 70 | +DisableLocalAuth : False |
| 71 | +MinimumTlsVersion : 1.2 |
| 72 | +KeySource : |
| 73 | +Identity : |
| 74 | +IdentityType : |
| 75 | +IdentityId : |
| 76 | +EncryptionConfig : |
38 | 77 | ```
|
39 | 78 |
|
40 | 79 | ## Create an event hub
|
41 | 80 |
|
42 |
| -Now that you have an Event Hubs namespace, create an event hub within that namespace: |
43 |
| -Allowed period for `MessageRetentionInDays` is between 1 and 7 days. |
| 81 | +Now that you have an Event Hubs namespace, create an event hub within that namespace by running the following command. |
44 | 82 |
|
45 | 83 | ```azurepowershell-interactive
|
46 |
| -New-AzEventHub -ResourceGroupName myResourceGroup -NamespaceName namespace_name -EventHubName eventhub_name -MessageRetentionInDays 3 |
| 84 | +$ehubName="myEventHub" |
| 85 | +New-AzEventHub -ResourceGroupName $rgName -NamespaceName $namespaceName -EventHubName $ehubName |
| 86 | +``` |
| 87 | +You see output similar to the following one. |
| 88 | + |
| 89 | +```bash |
| 90 | +ArchiveNameFormat : |
| 91 | +BlobContainer : |
| 92 | +CaptureEnabled : |
| 93 | +CreatedAt : 3/13/2023 10:26:07 PM |
| 94 | +DataLakeAccountName : |
| 95 | +DataLakeFolderPath : |
| 96 | +DataLakeSubscriptionId : |
| 97 | +DestinationName : |
| 98 | +Encoding : |
| 99 | +Id : /subscriptions/00000000000-0000-0000-0000-00000000000000/resourceGroups/myResourceGroup162 |
| 100 | + 5872532/providers/Microsoft.EventHub/namespaces/myNamespace143349827/eventhubs/myEven |
| 101 | + tHub |
| 102 | +IntervalInSeconds : |
| 103 | +Location : eastus |
| 104 | +MessageRetentionInDays : 7 |
| 105 | +Name : myEventHub |
| 106 | +PartitionCount : 4 |
| 107 | +PartitionId : {0, 1, 2, 3} |
| 108 | +ResourceGroupName : myResourceGroup1625872532 |
| 109 | +SizeLimitInBytes : |
| 110 | +SkipEmptyArchive : |
| 111 | +Status : Active |
| 112 | +StorageAccountResourceId : |
| 113 | +SystemDataCreatedAt : |
| 114 | +SystemDataCreatedBy : |
| 115 | +SystemDataCreatedByType : |
| 116 | +SystemDataLastModifiedAt : |
| 117 | +SystemDataLastModifiedBy : |
| 118 | +SystemDataLastModifiedByType : |
| 119 | +Type : Microsoft.EventHub/namespaces/eventhubs |
| 120 | +UpdatedAt : 3/13/2023 10:26:07 PM |
47 | 121 | ```
|
48 | 122 |
|
49 | 123 | Congratulations! You have used Azure PowerShell to create an Event Hubs namespace, and an event hub within that namespace.
|
|
0 commit comments