简体   繁体   English

谁是rabbitmq 集群管理员? 如何从集群中获取数据?

[英]Who is rabbitmq cluster manager? How can I get data from cluster?

I created rabbitmq cluster.我创建了rabbitmq集群。 There are three nodes one master two slaves.共有三个节点,一主二从。 When master dies, who decides which slave is the new master.当主人去世时,谁来决定哪个奴隶是新主人。 Who is cluster manager?谁是集群管理员? And How can I get data from cluster.以及如何从集群中获取数据。 I can get message from every node from cluster but For example: I am getting data from master node, but when master node is dead, I need to connect to other node manually.我可以从集群的每个节点获取消息,但是例如:我正在从主节点获取数据,但是当主节点死亡时,我需要手动连接到其他节点。 But I want to connect to cluster and Whenever master dies, I could get message from another node?但是我想连接到集群并且每当 master 死掉时,我可以从另一个节点收到消息吗?

If the queue master node stops, your application will receive a "connection lost" exception.如果队列主节点停止,您的应用程序将收到“连接丢失”异常。 You then act upon this exception to connect to any other node in the cluster.然后根据此异常采取行动以连接到集群中的任何其他节点。

You don't need to know anything about a "cluster manager".您不需要了解有关“集群管理器”的任何信息。 Just connect to another node.只需连接到另一个节点。

The RabbitMQ Java client library supports automatic recovery for connections and topologies. RabbitMQ Java 客户端库支持连接和拓扑的自动恢复。


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.注意: RabbitMQ 团队会监控rabbitmq-users邮件列表,并且只是偶尔在 StackOverflow 上回答问题。

There's not sth like "cluster manager" .没有像“集群管理器”这样的东西 The nodes in a RabbitMQ cluster use the Raft algorithm for distributed consensus and elect their leader (see http://thesecretlivesofdata.com/raft ). RabbitMQ 集群中的节点使用 Raft 算法进行分布式共识并选举他们的领导者(参见http://thesecretlivesofdata.com/raft )。

On the other hand, RabbitMQ Java Client API already could manage disconnections as in the scenario that you pose.另一方面,RabbitMQ Java Client API 已经可以像您提出的场景一样管理断开连接。 New connections are recoverable by default (see https://www.rabbitmq.com/api-guide.html#connection-recovery ).默认情况下,新连接是可恢复的(请参阅https://www.rabbitmq.com/api-guide.html#connection-recovery )。

You could use this snippet as an example to create connections to several nodes (each String in the addressesStr List should be like node_ip:port ):您可以使用此代码段作为示例来创建与多个节点的连接( addressesStr列表中的每个字符串应类似于node_ip:port ):

  public Connection crateConnection(final List<String> addressesStr)
      throws IOException, TimeoutException {
    final ConnectionFactory factory = new ConnectionFactory();
    final List<Address> addresses = new ArrayList<>();

    for (final String address : addressesStr) {
      final String[] addr = address.split(":");
      final String host = addr[0];
      final var port = Integer.parseInt(addr[1]);
      addresses.add(new Address(host, port));
    }

    return factory.newConnection(addresses);
  }

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

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