0
votes

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.

1

1 Answers

3
votes

PairedNamespaces feature is not documented the way to make it easy to either understand or use. When you send a message and the primary namespace goes down, the client will try and eventually throw a MessagingCommunicationException. I wish it would be a designated exception to indicate that a failover will take place, but it's just a standard messaging exception and marked as transient. If you retry that message again, it will be sent via the secondary namespace.

I have a blog post on this that has more details/code.