Azure 服务总线:无法访问主命名空间时插入 PairedNamespaces

Azure Service Bus: PairedNamespaces insertion when Primary namespace is unreachable

我正在模拟 Azure 数据中心的故障以及服务总线在配对命名空间的情况下处理插入的方式。

ms docs 指出:

Upon failure to send to the primary queue, the sender begins sending messages to a randomly chosen backlog queue

但是,我注意到队列 client/message 发件人总是试图访问主命名空间,并且从不切换到辅助命名空间。

    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;
    }

并发送测试消息:

            var factory = GetFactory();

            var messageSender = factory.CreateMessageSender(_queueName);

            var msg = new BrokeredMessage(partition)
            {
                PartitionKey = partition,
                SessionId = partition

            };
            messageSender.Send(msg);

我测试它的方法是将虚拟 IP 关联到主机文件中的主命名空间 URL。发送失败并出现超时异常(每个后续请求都会出现这种情况)。

我猜 ping 任务没有选择切换,因为我的发件人从不尝试联系辅助命名空间。问题出在哪里?

值得一提的是,辅助命名空间中的备份队列已正确创建。

PairedNamespaces 功能未记录在案,以使其易于理解或使用。当您发送消息并且主命名空间关闭时,客户端将尝试并最终抛出 MessagingCommunicationException。我希望它是一个指定的异常来指示将发生故障转移,但它只是一个标准的消息传递异常 and 标记为瞬态。 如果您再次重试该消息,它将通过辅助命名空间发送。

我有一个 blog post 关于这个还有更多 details/code。