首页 > 解决方案 > RabbitMQ C# 客户端从具有仲裁队列的集群上的节点故障中恢复

问题描述

我已经设置了一个带有仲裁持久队列的三节点 RabbitMQ 集群。

我试图找出如何实现一种健壮的方法,以在节点故障的情况下保持生产者和消费者端(两个 .NET Core 进程)的运行。

我在ConnectionFactory课堂上使用以下选项:

var factory = new ConnectionFactory
{
    HostName = hostname,
    AutomaticRecoveryEnabled = true,
    TopologyRecoveryEnabled = true,
    VirtualHost = vhost
};

但是,在启动生产者和消费者测试过程(试图淹没队列)之后,每当我停止集群上的主节点时,客户端永远不会从这种情况中恢复,并且OperationInterruptedException每次调用BasicPublish(在生产者上)时都会抛出一个或BasicAck(在消费者身上)。

客户端使用从三个节点中选择的随机 ip 连接到集群(根据循环 dns 解析给出)。

我在某处读到,对于持久的经典非镜像队列,这是预期的行为,但是仲裁队列呢?它们不应该是镜像队列的更高效版本(尽管有一些限制)吗?

有没有在我的客户端中实现所有重新连接逻辑的情况下从单个节点故障中恢复的方法?

标签: c#rabbitmqclientcluster-computing

解决方案


从我在ConnectionFactory课堂上看到的内容来看,您可以在创建连接时指定主机名列表(而不是在声明工厂的步骤中)。你试过这个吗?

// Summary:
//     Create a connection using a list of hostnames using the configured port. By default
//     each hostname is tried in a random order until a successful connection is found
//     or the list is exhausted using the DefaultEndpointResolver. The selection behaviour
//     can be overriden by configuring the EndpointResolverFactory.
//
// Parameters:
//   hostnames:
//     List of hostnames to use for the initial connection and recovery.
//
// Returns:
//     Open connection
//
// Exceptions:
//   T:RabbitMQ.Client.Exceptions.BrokerUnreachableException:
//     When no hostname was reachable.
public IConnection CreateConnection(IList<string> hostnames);

推荐阅读