用周末休息时间,阿堂这里推出了最后一篇《分布式消息队列中间件系列研究之阿堂教程(高级篇)》,这里阿堂是分享的关于zookeeper集群+metaq(broker的集群)搭建篇。这样,分布式消息队列的使用才算划上了一个较为圆满的句号。
因为资源有限的关系,阿堂是在本机win7环境,使用同一个ip,不同的port正常运行起来 zookeeper集群+metaq broker的集群了,效果见下图。实际场景中是使用的不同的ip来搭建的。
分布式消息队列中间件系列研究之阿堂教程(高级篇)

然后阿堂运行上篇文章中提到的producer发布者的测试代码,效果如下。这时候,发布者会取到zookeeper集群中的某一台zookeeper服务器,连接正常了。
分布式消息队列中间件系列研究之阿堂教程(高级篇)

这时候,阿堂为了检测zookeeper集群是否起作用了,阿堂故意再用生产者发布一次消息,这时候,发现生产者是连接了另一个zookeeper服务器了。这充分说明,生产者每次连接的都可能是zookeeper集群中的某一台服务器,zookeeper集群已经完全起到作用了。测试效果如下。
分布式消息队列中间件系列研究之阿堂教程(高级篇)


接着,阿堂继续运用 消费者开始订阅消息,发现订阅消息一切正常,订阅的时候已经连接上了两台meta的broker集群了。这说明 meta的broker集群也是起到了作用。
分布式消息队列中间件系列研究之阿堂教程(高级篇)

分布式消息队列中间件系列研究之阿堂教程(高级篇)


至此时为止,已经充分说明阿堂的zookeeper集群+meta的broker集群已经是正常运行了。

------------------------------------------------------------
阿堂总结
1. zookeeper的集群比较简单,网上有很多的介绍,这里阿堂就不再罗嗦了。
2. meta的broker集群,主要是server.ini文件的介绍
broker0的server.ini文件配置

[system]
brokerId=0
numPartitions=5
serverPort=8123
unflushThreshold=0
unflushInterval=10000
maxSegmentSize=1073741824
maxTransferSize=1048576
deletePolicy=delete,168
deleteWhen=0 0 6,18 * * ?
flushTxLogAtCommit=1
stat=true

;; Update consumers offsets to current max offsets when consumers offsets are out of range of current broker's messages.
;; It must be false in production.But recommend to be true in development or test.
updateConsumerOffsets=true

[zookeeper]
zk.zkConnect=192.168.1.104:2181,192.168.1.104:2182,192.168.1.104:2183
zk.zkSessionTimeoutMs=30000
zk.zkConnectionTimeoutMs=30000
zk.zkSyncTimeMs=5000

;; Topics section
[topic=test]

[topic=meta-test]

[topic=email]

broker1的server.ini文件配置

[system]
brokerId=1
numPartitions=5
serverPort=9124
unflushThreshold=0
unflushInterval=10000
maxSegmentSize=1073741824
maxTransferSize=1048576
deletePolicy=delete,168
deleteWhen=0 0 6,18 * * ?
flushTxLogAtCommit=1
stat=true

;; Update consumers offsets to current max offsets when consumers offsets are out of range of current broker's messages.
;; It must be false in production.But recommend to be true in development or test.
updateConsumerOffsets=true

[zookeeper]
zk.zkConnect=192.168.1.104:2181,192.168.1.104:2182,192.168.1.104:2183
zk.zkSessionTimeoutMs=30000
zk.zkConnectionTimeoutMs=30000
zk.zkSyncTimeMs=5000

;; Topics section
[topic=test]

[topic=meta-test]

[topic=email]

3. 项目代码中 metaq.ini 文件的配置

zookeeper=192.168.1.104:2181,192.168.1.104:2182,192.168.1.104:2183
messagedir=D:\\metaq\\mmp\\logs