Azure Service Bus Geo-disaster recovery
To learn more about Azure Service Bus, please visit our marketing page.
To learn more about our Geo-DR feature in general please follow this link.
This sample shows how to:
- Achieve Geo-DR for an Service Bus namespace.
- Create a namespace with live metadata replication between two customer chosen regions
This sample consists of three parts:
- The main scenario showing management (Setup, failover, remove pairing) of new or existing namespaces sample can be found here
- The scenario in which you want to use an existing namespace name as alias can be found here. Make sure to thoroughly look through the comments as this diverges slightly from the main scenario. Examine both, App.config and Program.cs. Note: If you do not failover but just do break pairing, there is no need to execute delete alias as namespace name and alias are the same. If you do failover you would need to delete the alias if you would want to use the namespace outside of a DR setup.
- A sample on how to access the alias connection string which can be found here.
In order to get started using the sample (as it uses the Service Bus management libraries), you must authenticate with Azure Active Directory (AAD). This requires you to authenticate as a Service Principal, which provides access to your Azure resources. To obtain a service principal please do the following steps:
- Go to the Azure Portal and select Azure Active Directory in the left menu.
- Create a new Application under App registrations / + New application registration.
- The application should be of type Web app / API.
- You can provide any URL for your application as sign on URL.
- Navigate to your newly created application
- Application or AppId is the client Id. Note it down as you will need it for the sample.
- Select keys and create a new key. Note down the Value as you won't be able to access it later.
- Go back to the root Azure Active Directory and select properties.
- Note down the Directory ID as this is your TenantId.
- You must have ‘Owner’ permissions under Role for the resource group that you wish to run the sample on. Regardless if you want to use an existing namespace or create a new one, make sure to add the newly created application as owner under Access Control (IAM).
For more information on creating a Service Principal, refer to the following articles:
- Use the Azure Portal to create Active Directory application and service principal that can access resources
- Use Azure PowerShell to create a service principal to access resources
- Use Azure CLI to create a service principal to access resources
Required NuGet packages
- Microsoft.IdentityModel.Clients.ActiveDirectory - used to authenticate with AAD
Running the sample
- Please use Visual Studio 2017
- Make sure all assemblies are in place.
- Populate the regarding values in the App.config.
- Build the solution.
- Make sure to execute on Screen option A before any other option.
The Geo DR actions could be
CreatePairing For creating a paired region. After this, you should see metadata (i.e. Queues, Topics and Subscriptions replicated to the secondary namespace).
FailOver Simulating a failover. After this action, the secondary namespace becomes the primary
BreakPairing For breaking the pairing between a primary and secondary namespace
DeleteAlias For deleting an alias, that contains information about the primary-secondary pairing
GetConnectionStrings In a Geo DR enabled namespace, the Service Bus should be accessed only via the alias. This is because, the alias can point to either the primary Service Bus or the failed over Service Bus. This way, the user does not have to adjust the connection strings in his/her apps to point to a different Service Bus in the case of a failover.
The way to get the alias connection string is shown in a seperate console app which you can also use to test your newly geo paired namespaces. It can be found here.
Note: The AAD access data for the GeoDR sample must also be used for the Test sample.