简体   繁体   English

Azure 服务总线配对命名空间 - 模拟故障转移

[英]Azure service bus paired namespace - simulate failover

I am working with azure service bus paired namespace and need to be able to simulate a failover to the secondary namespace.我正在使用 azure 服务总线配对命名空间,并且需要能够模拟到辅助命名空间的故障转移。 I did kind of have this working by entering an incorrect connection string for the primary namespace and saw it fail over and send the message to the secondary namespace.我确实通过为主要命名空间输入了错误的连接字符串来实现这一点,并看到它发生故障转移并将消息发送到辅助命名空间。 This no longer seems to do the trick.这似乎不再奏效。 I can not find a way through the azure management portal or anywhere else to take a namespace offline.我无法通过 azure 管理门户或其他任何地方找到使命名空间脱机的方法。 Anyone any ideas how to do this?任何人有任何想法如何做到这一点?

Here is my code for reference这是我的代码供参考

var pairedNamespaceConfiguration = this.pairedNamespaceConfigurationDictionary[configurationKey];
MessagingFactory factory = MessagingFactory.CreateFromConnectionString(pairedNamespaceConfiguration.PrimaryNamespace.ConnectionString);
MessagingFactory secondaryMessagingFactory = MessagingFactory.CreateFromConnectionString(pairedNamespaceConfiguration.SecondaryNamespace.ConnectionString);
NamespaceManager secondaryNamespaceManager = NamespaceManager.CreateFromConnectionString(pairedNamespaceConfiguration.SecondaryNamespace.ConnectionString);

SendAvailabilityPairedNamespaceOptions sendAvailabilityOptions = new SendAvailabilityPairedNamespaceOptions(secondaryNamespaceManager, secondaryMessagingFactory, pairedNamespaceConfiguration.BacklogQueueCount, TimeSpan.FromSeconds(pairedNamespaceConfiguration.FailoverIntervalSeconds), false);
factory.PairNamespaceAsync(sendAvailabilityOptions).Wait();
MessageSender messageSender = factory.CreateMessageSender(pairedNamespaceConfiguration.PathName);
string messageContent = JsonConvert.SerializeObject(message);

using(BrokeredMessage brokeredMessage = new BrokeredMessage(messageContent))
{
    messageSender.Send(brokeredMessage);
}

Modify your \\Windows\\system32\\drivers\\etc\\hosts file to point the original namespace to something like 127.0.0.1.修改您的 \\Windows\\system32\\drivers\\etc\\hosts 文件以将原始命名空间指向 127.0.0.1 之类的内容。 This will make the original namespace connection fail.这将使原始命名空间连接失败。

I'm using this example Geo-replication with Service Bus Relayed Messages to implement the same think.我正在使用此示例 地理复制和服务总线中继消息来实现相同的想法。 Maybe it's useful for you also.也许它对你也有用。

All Service Bus entities reside in a namespace.所有服务总线实体都驻留在一个命名空间中。 A namespace is affiliated to a datacenter.命名空间附属于数据中心。 To allow for a failover between datacenters, the user must create one Service Bus and ACS namespace (in case ACS is used) per datacenter.为了允许数据中心之间的故障转移,用户必须为每个数据中心创建一个服务总线和 ACS 命名空间(如果使用 ACS)。 Any Service Bus relay that needs to remain accessible in the presence of datacenter failures must be created in both namespaces.在出现数据中心故障时需要保持可访问的任何服务总线中继都必须在两个命名空间中创建。

The server opens two NetTcp relay endpoints, one in each of the two namespaces.服务器打开两个 NetTcp 中继端点,在两个命名空间中的每一个中都有一个。 The server processes any request that is received via one of these endpoints.服务器处理通过这些端点之一接收到的任何请求。 Note that the two relays have to have different names (.eg, address of primary relay is sb://myPrimaryNamespace.servicebus.windows.net/myService-primary and b://mySecondaryNamespace.servicebus.windows.net/myService-secondary).请注意,两个中继必须具有不同的名称(例如,主中继的地址是 sb://myPrimaryNamespace.servicebus.windows.net/myService-primary 和 b://mySecondaryNamespace.servicebus.windows.net/myService-secondary )。

The client considers one of the two replicated relays as the active relay and the other one as a backup.客户端将两个复制的中继之一视为活动中继,另一个视为备份。 It opens a channel to the active relay and invokes methods on the service.它打开一个通向活动中继的通道并调用服务上的方法。 If the invocation fails with any exception that is not part of the service contract, the client abandons the channel, opens a channel to the backup relay, and invokes the service method again.如果调用因任何不属于服务合同的异常而失败,则客户端放弃通道,打开一个到备份中继的通道,并再次调用服务方法。 The client will consider the new channel to be the active channel and continues to use that channel until the next fault occurs.客户端会将新通道视为活动通道并继续使用该通道,直到发生下一个故障。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM