c# - RabbitMQ C# 客户端从具有仲裁队列的集群上的节点故障中恢复
问题描述
我已经设置了一个带有仲裁持久队列的三节点 RabbitMQ 集群。
我试图找出如何实现一种健壮的方法,以在节点故障的情况下保持生产者和消费者端(两个 .NET Core 进程)的运行。
我在ConnectionFactory
课堂上使用以下选项:
var factory = new ConnectionFactory
{
HostName = hostname,
AutomaticRecoveryEnabled = true,
TopologyRecoveryEnabled = true,
VirtualHost = vhost
};
但是,在启动生产者和消费者测试过程(试图淹没队列)之后,每当我停止集群上的主节点时,客户端永远不会从这种情况中恢复,并且OperationInterruptedException
每次调用BasicPublish
(在生产者上)时都会抛出一个或BasicAck
(在消费者身上)。
客户端使用从三个节点中选择的随机 ip 连接到集群(根据循环 dns 解析给出)。
我在某处读到,对于持久的经典非镜像队列,这是预期的行为,但是仲裁队列呢?它们不应该是镜像队列的更高效版本(尽管有一些限制)吗?
有没有在我的客户端中实现所有重新连接逻辑的情况下从单个节点故障中恢复的方法?
解决方案
从我在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);
推荐阅读
- rust - 如何在 Rust 中使用回形针实现 REST API,以便响应类型显示在 swagger ui 中
- php - 在多行模式下匹配 PHP 正则表达式时,这个神秘的换行符来自哪里?
- google-sheets - 大于单元格引用的查询总和不起作用 - Google 表格
- python - 用户已被删除/停用(由 GetDialogsRequest 引起)
- angular - Angular:如何将组件从父组件交互到子组件
- button - 如何解决按钮矩阵中的问题,其中按钮变高而不按下它?
- flutter - Dart 中的 VOID 和 DYNAMIC 功能有什么不同?
- javascript - 如何在Javascript中将秒转换为时间
- json - 自适应卡片 1.3 版
- regex - 查找不包含斜线的单词