Enable Event Hubs Geo-DR configurations using PowerShell
Published Mar 15 2019 12:59 PM 2,969 Views
First published on on Feb 22, 2018
Azure Event Hubs has released AzureRM.EventHub PowerShell Module 5.3.0 . With this version you can now configure your Geo-paired namespaces for Geo-DisasterRecovery. The cmdlets let you use the Alias and pair your primary and secondary namespaces. You can then failover to your paired namespace specified in your configuration.

What is the concept of alias?


To enable a Geo-DisasterRecovery feature on your namespace, you need to pair it with a secondary namespace. Therefore, when disaster strikes, you initiate a failover to your secondary namespace. This means that the clients connecting to the primary namespace with the connection string must be updated to the secondary namespace connection string. In production systems, this means a significant downtime. Can this be seamless? Azure Event Hubs Geo-DR feature provides you with the Alias concept. You provide an alias name when you pair the namespaces. This alias name will not only give you the geo-pair configuration, but also provide an alias connection string with a fully qualified domain name. This connection string can be used in the clients without needing an update even in the event of fail over.

Can I enable the Geo-DR feature on existing Event Hubs namespaces?


Yes, you can enable this feature on existing namespaces and is available in all regions.

The following script describes the steps of how Geo-DR can be done using PowerShell cmdlets.

Pre-requisites


Before you begin, you'll need the following:

Copy the following cmdlets into a text or .ps1 file. Use Window + X to open PowerShell command prompt with Admin rights. You can also open the PowerShell ISE as Admin and run the following script.
# Step 1 – Login to your Azure subscription
Login-AzureRmAccount

# Optional – you need this if you do not have Event Hubs module already installed
Install-Module AzureRM.EventHub

#Step 2 – following parameters are used while creating the resources
$location1 = “East US”
$location2 = “West US”
$resourceGroup = “eventhubgeodr_resourcegroup”
$primarynamespace = “eventhub_primarynamespace1”
$secondarynamespace = “eventhub_secondarynamespace1”
$aliasname = “eventhubalias1”

#Step 3 - Create Resource Group
New-AzureRmResourceGroup -Name $resourceGroup -Location $location1

#Step 4 - Create Event Hubs primary namespace
New-AzureRmEventHubNamespace – ResourceGroup $resourceGroup -NamespaceName $primarynamespace -Location $location1 -SkuName Standard

#Step 5 - Create Event Hubs secondary namespace
New-AzureRmEventHubNamespace – ResourceGroup $resourceGroup – NamespaceName $secondarynamespace -Location $location2 -SkuName Standard

#Step 6 – Create an alias and pairs the namespaces
New-AzureRmEventHubGeoDRConfiguration -ResourceGroupName $resourcegroup -Name $aliasname -Namespace $primarynamespace -Namespace $secondarynamespace

#Optional – you can obtain the alias details using this cmdlet
Get-AzureRmEventHubGeoDRConfiguration -ResourceGroup $resourcegroup -Name $aliasname -Namespace $primarynamespace

#Optional – you can break the pairing between the two namespaces if you desire to associate a different pairing. Break pair is initiated over primary only
Set-AzureRmEventHubGeoDRConfigurationBreakPair -ResourceGroup $resourcegroup -Name $aliasname -Namespace $primarynamespace

#Optional – create entities to test the meta data sync between primary and secondary namespaces
#Here we are creating an event hub
New-AzureRmEventHub -ResourceGroup $resourcegroup -Namespace $primarynamespace -Name “testeventhub1” –location $location1

#Optional – check if the created event hub was replicated
Get-AzureRmEventHub  -ResourceGroup $resourcegroup -Namespace $secondarynamespace -Name “testeventhub1”

#Step 7 – Initiate a failover. This will break the pairing and alias will now point to the secondary namespace. Failover is initiated over secondary only
Set-AzureRmEventHubGeoDRConfigurationFailOver -ResourceGreoup $resourcegroup -Name $aliasname -Namespace $secondarynamespace

#Step 8 – Remove the Geo-pairing and its configuration. This cmdlet would delete the alias
Remove-AzureRmEventHubGeoDRConfiguration -ResourceGroup $resourcegroup -Name $aliasname

#Optional – clean up the created resoucegroup
Remove-AzureRmResourceGroup -Name $resourcegroup
Enjoy this new tooling capability for Event Hubs and please leave us your valuable feedback and comments!



Happy event-ing!

Event Hubs team





Version history
Last update:
‎Jul 08 2020 12:52 PM
Updated by: