
Clustering(集群)
ActiveMQ 从多种不同的方面提供了集群的支持。
1、 Queue consumer clusters
ActiveMQ 支持订阅同一个 queue 的 consumers 上的集群。如果一个 consumer
失效,那么所有未被确认(unacknowledged)的消息都会被发送到这个 queue 上
其它的 consumers。如果某个 consumer 的处理速度比其它 consumers 更快,那么
这个 consumer 就会消费更多的消息。
需要注意的是,笔者发现 AcitveMQ5.0 版本的 Queue consumer clusters 存在
一个 bug:采用 AMQ Message Store,运行一个 producer,两个 consumer,并采
用如下的配置文件:
Xml 代码
<beans>
<broker xmlns="http://activemq.org/config/1.0" brokerName="BugBroker1"
useJmx="true">
<transportConnectors>
<transportConnector uri="tcp://localhost:61616"/>
</transportConnectors>
<persistenceAdapter>
<amqPersistenceAdapter directory="activemq-data/BugBroker1"
maxFileLength="32mb"/>
</persistenceAdapter>
</broker>
</beans>
那么经过一段时间后可能会报出如下错误:
ERROR[ActiveMQTransport:tcp:///127.0.0.1:1843-RecoveryListenerAdapter.java:58
-RecoveryListenerAdapter] Message id ID:versus-1837-1203915536609-0:2:1:1:419
could not be recovered from the data store!
Apache 官方文档说,此 bug 已经被修正,预定在 5.1.0 版本上体现。
2、 Broker clusters
一个常见的场景是有多个 JMS broker,有一个客户连接到其中一个 broker。
如果这个 broker 失效,那么客户会自动重新连接到其它的 broker。在 ActiveMQ
中使用 failover:// 协议来实现这个功能。ActiveMQ3.x 版本的 reliable://协议已经