Artemis集群--多个接受者的负载均衡。

问题描述 投票:0回答:1

我有一个由4个节点组成的Artemis集群(2个主节点,2个备份节点)。每一个broker都有2个接受器--一个用于核心协议,一个用于stomp协议(因为stomp需要前缀属性)。所以它们有不同的端口。

当我使用jms-client 2.x和ConnectionFactory从Spring Boot应用程序连接集群时,地址和消息在节点之间是负载均衡的。但当我尝试与stomp客户端交互时,它根本没有进行负载均衡。似乎是集群连接没有被识别。我不知道问题出在哪里。

文档 说,消息通过集群连接进行负载均衡。

这些集群连接允许消息在集群的节点之间流动,以平衡负载。

所以也许我需要更多的集群连接和连接器,这些连接和连接器是在 broker.xml?

我有一个STOMP客户端,用61613端口连接到第一个主节点。当我从另一个节点发送消息到第一个主节点时,我可以消耗它,我可以看到地址是在两个节点上创建的。一个像处于被动模式,有一个机架轮,一个主动模式,有一个文件夹符号,可以展开。这些地址,是从应用中创建的,每个都只是在一个节点上。

下面是一个主站和一个备份站的broker配置的片段。

主:

<connectors>
   <connector name="netty-connector">tcp://localhost:61616</connector>
</connectors>

<acceptors>
   <acceptor name="artemis">tcp://localhost:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor>
   <acceptor name="stomp">tcp://localhost:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true;anycastPrefix=/queue/;multicastPrefix=/topic/</acceptor>
</acceptors>


<!-- failover config -->
<ha-policy>
   <replication>
      <master>
         <check-for-live-server>true</check-for-live-server>
      </master>
   </replication>   
</ha-policy>

<broadcast-groups>
   <broadcast-group name="my-broadcast-group">
      <broadcast-period>5000</broadcast-period>
      <jgroups-file>test-jgroups-jdbc_ping.xml</jgroups-file>
      <jgroups-channel>active_broadcast_channel</jgroups-channel>
      <connector-ref>netty-connector</connector-ref>
   </broadcast-group>
</broadcast-groups>

<discovery-groups>
   <discovery-group name="my-discovery-group">
      <jgroups-file>test-jgroups-jdbc_ping.xml</jgroups-file>
      <jgroups-channel>active_broadcast_channel</jgroups-channel>
      <refresh-timeout>10000</refresh-timeout>
   </discovery-group>
</discovery-groups>

<cluster-connections>
   <cluster-connection name="my-cluster">
      <connector-ref>netty-connector</connector-ref>
      <retry-interval>500</retry-interval>
      <use-duplicate-detection>true</use-duplicate-detection>
      <message-load-balancing>ON_DEMAND</message-load-balancing>
      <max-hops>1</max-hops>
      <discovery-group-ref discovery-group-name="my-discovery-group"/>
   </cluster-connection>       
</cluster-connections>

备用

<connectors>
   <connector name="netty-connector">tcp://localhost:61617</connector>
   <connector name="server1-netty-live-connector">tcp://localhost:61616</connector>  
</connectors>

<acceptors>
   <acceptor name="artemis">tcp://localhost:61617?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor>
   <acceptor name="stomp">tcp://localhost:61614?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true;anycastPrefix=/queue/;multicastPrefix=/topic/</acceptor>
</acceptors>

<cluster-user>user</cluster-user>
<cluster-password>pw</cluster-password>

<!-- failover config -->
<ha-policy>
   <replication>
      <slave>
         <allow-failback>true</allow-failback>
      </slave>
   </replication>
</ha-policy>

<broadcast-groups>
   <broadcast-group name="my-broadcast-group">
      <broadcast-period>5000</broadcast-period>
      <jgroups-file>test-jgroups-jdbc_ping.xml</jgroups-file>
      <jgroups-channel>active_broadcast_channel</jgroups-channel>
      <connector-ref>netty-connector</connector-ref>
   </broadcast-group>
</broadcast-groups>

<discovery-groups>
   <discovery-group name="my-discovery-group">
      <jgroups-file>test-jgroups-jdbc_ping.xml</jgroups-file>
      <jgroups-channel>active_broadcast_channel</jgroups-channel>
      <refresh-timeout>10000</refresh-timeout>
   </discovery-group>
</discovery-groups>

<cluster-connections>
   <cluster-connection name="my-cluster">
      <connector-ref>netty-connector</connector-ref>
      <retry-interval>500</retry-interval>
      <use-duplicate-detection>true</use-duplicate-detection>
      <message-load-balancing>ON_DEMAND</message-load-balancing>
      <max-hops>1</max-hops>
      <discovery-group-ref discovery-group-name="my-discovery-group"/>
   </cluster-connection>
</cluster-connections>

谁能帮帮我?

spring-boot spring-jms stomp activemq-artemis
1个回答
1
投票

根据你提供的所有信息,到目前为止,一切似乎都很正常。你引用的文档中说。

这些集群连接可以让消息在集群的节点之间流动 以平衡负载

而当你向一个节点发送STOMP消息时,你能够从另一个节点消耗它,这意味着消息是通过集群连接在节点之间按需流动以平衡负载。

你不需要任何额外的集群连接或连接器。

要说明的是,集群中的每个经纪人都会有自己的一组地址、队列和消息,这取决于连接到它们的客户端在做什么。你不应该期望在集群的所有不同节点上看到所有相同的地址或队列--尤其是当你依靠自动创建地址和队列,而不是预先在 broker.xml.

也就是说,你 看到使用JMS客户端的应用程序(例如您的Spring应用程序)和使用STOMP的应用程序的一些不同行为。这是因为STOMP协议没有定义任何与高级概念相关的东西,比如连接负载均衡、故障转移等。STOMP是一个非常简单的协议,客户端通常也很简单。此外,Spring应用通常会创建多个连接。这些连接在集群中的节点间以循环的方式进行平衡,这几乎可以肯定为什么那些相关的地址和队列会出现在所有节点上,而你的单个STOMP客户端的地址和队列不会出现。客户端连接负载均衡将在下面的文章中进一步讨论。文件.

讯息 是由节点本身分发的,与使用的协议无关。这就是集群连接的全部目的--将消息转发给其他节点。

客户端 连接 不能由节点本身自动分发,因为那需要重定向,而且不是所有协议(如STOMP)都支持这些语义。

© www.soinside.com 2019 - 2024. All rights reserved.