1. 默认情况下,ActiveMQ会平均分配消息到多个Consumers。
可以看到,3个Consumer,每个Consumer都消费了20条消息。
2. 现在来看一个复杂一些的情况,部署拓扑图如下:
Broker-1 单向转发消息到 Broker-2
Producer 发送消息到Broker-1
Consumer-1监听Broker-1,距离消息比较“近”。
Consumer-2监听Broker-2,距离消息比较“远”。
参考文献:
1. http://akuntamukkala.blogspot.com/2014/02/activemq-network-of-brokers-explained.html
2. http://akuntamukkala.blogspot.com/2014/02/activemq-network-of-brokers-explained_28.html
3. http://akuntamukkala.blogspot.com/2014/03/activemq-network-of-brokers-explained.html
4. http://akuntamukkala.blogspot.com/2014/03/activemq-network-of-brokers-explained_26.html
5. http://akuntamukkala.blogspot.com/2014/05/activemq-network-of-brokers-explained.html
可以看到,3个Consumer,每个Consumer都消费了20条消息。
2. 现在来看一个复杂一些的情况,部署拓扑图如下:
Broker-1 单向转发消息到 Broker-2
Producer 发送消息到Broker-1
Consumer-1监听Broker-1,距离消息比较“近”。
Consumer-2监听Broker-2,距离消息比较“远”。
Broker-1上的activemq.xml的networkConnectors配置片段如下:
<networkConnectors>
<networkConnector
name="T:broker1->broker2"
uri="static:(tcp://localhost:61626)"
duplex="false"
decreaseNetworkConsumerPriority="false"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker1->broker2"
uri="static:(tcp://localhost:61626)"
duplex="false"
decreaseNetworkConsumerPriority="false"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<networkConnector
name="T:broker1->broker2"
uri="static:(tcp://localhost:61626)"
duplex="false"
decreaseNetworkConsumerPriority="false"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker1->broker2"
uri="static:(tcp://localhost:61626)"
duplex="false"
decreaseNetworkConsumerPriority="false"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
networkTTL="2",表示最多允许经过几个Broker,这里只经过了一个Broker,小于2。
在Broker-1的Console上,查看Queue的详细信息:
发现100条消息依然平均分配到了两个Consumer上,各自消费了50条。
修改Broker-1上的activemq.xml的networkConnectors配置片段如下:
<networkConnectors>
<networkConnector
name="T:broker1->broker2"
uri="static:(tcp://localhost:61626)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker1->broker2"
uri="static:(tcp://localhost:61626)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<networkConnector
name="T:broker1->broker2"
uri="static:(tcp://localhost:61626)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker1->broker2"
uri="static:(tcp://localhost:61626)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
在Broker-1的Console上,查看Queue的详细信息:
发现这次100条消息全被分配给了Consumer-1,因为它距离消息最“近”。参考文献:
1. http://akuntamukkala.blogspot.com/2014/02/activemq-network-of-brokers-explained.html
2. http://akuntamukkala.blogspot.com/2014/02/activemq-network-of-brokers-explained_28.html
3. http://akuntamukkala.blogspot.com/2014/03/activemq-network-of-brokers-explained.html
4. http://akuntamukkala.blogspot.com/2014/03/activemq-network-of-brokers-explained_26.html
5. http://akuntamukkala.blogspot.com/2014/05/activemq-network-of-brokers-explained.html
没有评论:
发表评论