【发布时间】:2020-06-05 08:25:39
【问题描述】:
我有一个包含 4 个节点(2 个主节点,2 个备份节点)的 Artemis 集群。每个代理都有 2 个接受器 - 一个用于核心协议,一个用于 stomp 协议(因为 stomp 需要前缀属性)。所以他们有不同的端口。
当我使用 jms-client 2.x 和 ConnectionFactory 从 Spring Boot 应用程序连接集群时,地址和消息在节点之间进行负载平衡。但是当我尝试与 stomp 客户端交互时,它根本没有负载平衡。似乎无法以某种方式识别集群连接。我不确定可能是什么问题。
The documentation 表示消息通过集群连接进行负载平衡:
这些集群连接允许消息在集群的节点之间流动以平衡负载。
所以也许我需要更多的集群连接和连接器,它们在broker.xml 中配置?
我有一个 STOMP 客户端,它使用端口 61613 连接到第一个主节点。当我将消息发送到第一个主节点时,我可以使用来自另一个节点的消息,并且我可以看到两个节点上都创建了地址.一种是带有齿条轮的被动模式,另一种是带有文件夹符号的主动模式,可以扩展。从应用程序创建的地址都只在一个节点上。
以下显示了一个主代理和一个备份代理的代理配置的 sn-ps:
主人:
<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>
谁能帮忙?
【问题讨论】:
-
感谢@JustinBertram 提出您的问题。 “负载平衡良好”在我的上下文中意味着地址和消息在节点之间进行负载平衡。 “也许我需要更多”是指集群连接和连接器,它们在 broker.xml 中配置。由于连接器指的是端口 61616 和应用程序使用的 artemis-acceptor,我想为 stomp-port/stomp-acceptor 添加一些。但到目前为止,这些尝试都没有奏效。
-
我有一个 STOMP 客户端,它使用端口 61613 连接到第一个主节点。现在我尝试了您的建议:当我将消息发送到一个节点时,我可以使用来自另一个节点的消息。跨度>
-
我可以看到,地址是在两个节点上创建的。一种是带有齿条轮的被动模式,另一种是带有文件夹符号的主动模式,可以扩展。从应用程序创建的地址都只在一个节点上。
-
我更新了您的问题以包含这些重要信息。
标签: spring-boot spring-jms stomp activemq-artemis