I'm simulating the failure of an Azure data center and the way the service bus is dealing with insertions in case of paired namespaces.
The ms docs states that:
Upon failure to send to the primary queue, the sender begins sending messages to a randomly chosen backlog queue
However, I noticed that the queue client/message sender is always trying to hit the primary namespace and is never switching to the secondary one.
private MessagingFactory GetFactory(bool isReceiver = false)
{
var primaryConnectionString = PrimaryConnectionString();
var secondaryConnectionString = SecondaryConnectionString();
var primaryFactory =
MessagingFactory.CreateFromConnectionString(primaryConnectionString);
var secondaryMessagingFactory = MessagingFactory.CreateFromConnectionString(secondaryConnectionString);
var secondaryNamespaceManager = NamespaceManager.CreateFromConnectionString(secondaryConnectionString);
var sendAvailabilityOptions = new SendAvailabilityPairedNamespaceOptions(secondaryNamespaceManager,
secondaryMessagingFactory, 1, TimeSpan.FromSeconds(5), isReceiver);
primaryFactory.PairNamespaceAsync(sendAvailabilityOptions).Wait();
return primaryFactory;
}
and for sending a test message:
var factory = GetFactory();
var messageSender = factory.CreateMessageSender(_queueName);
var msg = new BrokeredMessage(partition)
{
PartitionKey = partition,
SessionId = partition
};
messageSender.Send(msg);
The way I'm testing it is by associating a dummy IP to the primary namespace URL in the hosts file. The sending fails with a timeout exception (that being the case of every subsequent request).
I guess the ping task is not choosing to switch because my sender never tries to contact the secondary namespace. Where can the problem be?
Worth mentioning that the backup queue in the secondary namespace is correctly created.