Jul 18 2024 10:40 AM
Disaster recovery (DR) is crucial for ensuring business continuity and minimizing downtime. While the Azure Service Bus Basic tier doesn't support advanced Geo-disaster recovery (Geo-DR) or Geo-Replication(Public Preview) features like the Premium tiers, you can still implement a custom DR strategy. This guide will walk you through setting up a disaster recovery solution for Azure Service Bus using the Basic tier.
Before starting, make sure you have:
Create the Primary Namespace:
Create the Secondary Namespace:
Since the Basic tier does not support Geo-DR, you'll need to manually synchronise messages between the primary and secondary namespaces. This can be achieved through custom code or third-party tools.
Implement Message Synchronisation:
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
public static class MessageSynchroniser
{
private static string primaryConnectionString = "<PrimaryNamespaceConnectionString>";
private static string secondaryConnectionString = "<SecondaryNamespaceConnectionString>";
private static string queueName = "<QueueName>";
private static IQueueClient secondaryQueueClient;
[FunctionName("MessageSynchroniser")]
public static async Task Run([ServiceBusTrigger(queueName, Connection = "primaryConnectionString")] Message message, ILogger log)
{
secondaryQueueClient = new QueueClient(secondaryConnectionString, queueName);
try
{
var secondaryMessage = new Message(Encoding.UTF8.GetBytes(message.Body))
{
ContentType = message.ContentType,
Label = message.Label,
MessageId = message.MessageId,
CorrelationId = message.CorrelationId,
UserProperties = message.UserProperties
};
await secondaryQueueClient.SendAsync(secondaryMessage);
log.LogInformation($"Message synchronised to secondary namespace: {message.MessageId}");
}
catch (Exception ex)
{
log.LogError($"Error synchronising message: {ex.Message}");
}
finally
{
await secondaryQueueClient.CloseAsync();
}
}
}
In the event of a disaster, you will need to manually failover to the secondary namespace.
Update Connection Strings:
Communicate the Change:
Once the primary region is operational again, you can switch back to the primary namespace.
Resynchronise Messages:
Update Connection Strings:
While the Azure Service Bus Basic tier lacks built-in Geo-DR capabilities, you can still create a robust disaster recovery solution through custom synchronization and failover procedures. By following the steps outlined in this guide, you can ensure your messaging infrastructure is resilient and prepared for any disruptions. Regular testing and monitoring will help maintain the effectiveness of your DR strategy.
Feel free to reach out if you have any questions or need further assistance. Happy configuring!
-- Santosh Patkar
Aug 27 2024 11:20 PM
Aug 27 2024 11:23 PM
Aug 29 2024 01:56 AM
@Rizwan8668 : Thank you for the reply.
I have automated the process of creating azure app service and deploying web app and API to it (it's a DR plan since pricing is too high to use active active/passive architecture). And the application running in app service is going to use this messaging queues. Practically speaking, we don't require message sync, right? because as soon as primary region goes down and If I bring back the application into secondary region the app service in secondary region will be configured to secondary service bus name space and also primary service bus queue will be processed. The secondary just starts new queue.