RabbitMQ 中所有节点上的队列声明
Queue declaration on all nodes in RabbitMQ
我有一个 Rabbitmq 集群设置(没有 HA)。我的消费者是 spring 应用程序,它提供开箱即用的故障转移机制,连接到下一个可用节点。
由于队列不是镜像的,如果我预先声明队列并且当第一个节点出现故障时,将建立到第二个节点的连接是否可以。这有意义吗?
另一个问题,假设我在 Rabbitmq 集群上有一个负载平衡。我的应用程序使用负载平衡进行连接。队列是在所有节点上声明还是根据LB的路由策略在节点上声明。
对于第一种情况,是的,当建立连接时,将在故障转移代理实例上声明队列。
如果要在所有节点上预先声明,则每个节点都需要一个连接工厂,每个连接工厂需要一个 RabbitAdmin
。
您还需要一些东西来打开每个连接(RabbitAdmin
将自己注册为连接侦听器)。
您可以通过添加一个 bean 来实现 SmartLifecycle
并在每个连接工厂上调用 createConnection()
。
您还可以有选择地声明元素。参见 Conditional Declaration。
By default, all queues, exchanges, and bindings are declared by all RabbitAdmin
instances (that have auto-startup="true"
) in the application context.
Starting with the 1.2 release, it is possible to conditionally declare these elements. This is particularly useful when an application connects to multiple brokers and needs to specify with which broker(s) a particular element should be declared.
我有一个 Rabbitmq 集群设置(没有 HA)。我的消费者是 spring 应用程序,它提供开箱即用的故障转移机制,连接到下一个可用节点。
由于队列不是镜像的,如果我预先声明队列并且当第一个节点出现故障时,将建立到第二个节点的连接是否可以。这有意义吗?
另一个问题,假设我在 Rabbitmq 集群上有一个负载平衡。我的应用程序使用负载平衡进行连接。队列是在所有节点上声明还是根据LB的路由策略在节点上声明。
对于第一种情况,是的,当建立连接时,将在故障转移代理实例上声明队列。
如果要在所有节点上预先声明,则每个节点都需要一个连接工厂,每个连接工厂需要一个 RabbitAdmin
。
您还需要一些东西来打开每个连接(RabbitAdmin
将自己注册为连接侦听器)。
您可以通过添加一个 bean 来实现 SmartLifecycle
并在每个连接工厂上调用 createConnection()
。
您还可以有选择地声明元素。参见 Conditional Declaration。
By default, all queues, exchanges, and bindings are declared by all
RabbitAdmin
instances (that haveauto-startup="true"
) in the application context.Starting with the 1.2 release, it is possible to conditionally declare these elements. This is particularly useful when an application connects to multiple brokers and needs to specify with which broker(s) a particular element should be declared.