2015年10月14日星期三

AMQ_003:A-MQ 功能演示3:Master/Slave Failover 高可用架构

环境:JBoss A-MQ 6.0.0

1. Master/Slave Failover
Master/Slave Failover是一种高可用解决方案,其实现的重要原理就是 Master/Slave 节点必须指向同一个 persistence store。
A-MQ 使用排它锁来访问 persistence store,先拿到这个锁的节点就是 Master 节点,其它节点是 Slave 节点,Slave 节点不断轮询以获得排它锁,在获得锁之前,它不会发起真正的连接。
一条消息在某一时刻只能存在于一个节点上,当消息所在的节点宕掉时,消息的持久化信息依然安全地保存在persistence store 中,等待其它正常的节点将其获取并发送。
除了使用同一个 persistence store(SAN)来实现Master/Slave Failover这种方式之外,还可以使用RHEL HA以及数据库复制方式实现。

(1)创建Master/Slave container
mq-create --create-container broker1,broker2 tolerant
输出如下:
MQ profile tolerant ready
Jmx Login for root: admin
Jmx Password for root:
Successfully created container broker1
Successfully created container broker2

(2)访问Fabric Management Console,查看tolerant Profile具体配置信息
找到 org.fusesource.mq.fabric.server-tolerant.properties,内容如下:

#Wed Oct 14 08:46:10 CST 2015
connectors=openwire
broker-name=tolerant
config=zk\:/fabric/configs/versions/1.0/profiles/mq-base/broker.xml
data=/Users/maping/Redhat/amq/demo/jboss-a-mq-6.0.0.redhat-024/data/tolerant
group=default
standby.pool=default

(3)生产者
java -jar mq-client.jar producer --brokerUrl discovery:fabric:default --user admin --password admin --destination queue://summit.test --count 10
brokerUrl 值为 discovery:fabric:default,是让 JBoss A-MQ 客户端使用自动发现机制去查找 ActiveMQ 节点的连接信息。
因为Fabric registry 在本地(就是本机),所以不需要提供 Dzookeeper.url=<host>:<port>,如果Fabric registry 不在本地,那么需要提供这个参数。
输出如下:
Using destination: queue://summit.test, on broker: discovery:fabric:default
[org.fusesource.mq.fabric.FabricDiscoveryAgent] : Using local ZKClient
[org.fusesource.fabric.zookeeper.internal.AbstractZKClient] : Starting StateChangeDispatcher
[org.apache.zookeeper.ZooKeeper] : Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
[org.apache.zookeeper.ZooKeeper] : Client environment:host.name=192.168.56.1
[org.apache.zookeeper.ZooKeeper] : Client environment:java.version=1.7.0_80
[org.apache.zookeeper.ZooKeeper] : Client environment:java.vendor=Oracle Corporation
[org.apache.zookeeper.ZooKeeper] : Client environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/jre
[org.apache.zookeeper.ZooKeeper] : Client environment:java.class.path=mq-client.jar
[org.apache.zookeeper.ZooKeeper] : Client environment:java.library.path=/Users/maping/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
[org.apache.zookeeper.ZooKeeper] : Client environment:java.io.tmpdir=/var/folders/3w/hlhsjmns5m9g6xv6xqk2864h0000gn/T/
[org.apache.zookeeper.ZooKeeper] : Client environment:java.compiler=
[org.apache.zookeeper.ZooKeeper] : Client environment:os.name=Mac OS X
[org.apache.zookeeper.ZooKeeper] : Client environment:os.arch=x86_64
[org.apache.zookeeper.ZooKeeper] : Client environment:os.version=10.10.5
[org.apache.zookeeper.ZooKeeper] : Client environment:user.name=maping
[org.apache.zookeeper.ZooKeeper] : Client environment:user.home=/Users/maping
[org.apache.zookeeper.ZooKeeper] : Client environment:user.dir=/Users/maping/Redhat/amq/demo/jboss-a-mq-6.0.0.redhat-024/extras
[org.apache.zookeeper.ZooKeeper] : Initiating client connection, connectString=localhost:2181 sessionTimeout=10000 watcher=org.fusesource.fabric.zookeeper.internal.ZKClient@7fe7f581
[org.apache.zookeeper.ClientCnxn] : Opening socket connection to server /fe80:0:0:0:0:0:0:1%1:2181
[org.apache.zookeeper.client.ZooKeeperSaslClient] : Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
[org.apache.zookeeper.ClientCnxn] : Socket connection established to fe80:0:0:0:0:0:0:1%1/fe80:0:0:0:0:0:0:1%1:2181, initiating session
[org.apache.zookeeper.ClientCnxn] : Session establishment complete on server fe80:0:0:0:0:0:0:1%1/fe80:0:0:0:0:0:0:1%1:2181, sessionid = 0x150656962ea0003, negotiated timeout = 10000
[org.apache.activemq.transport.discovery.DiscoveryTransport] : Adding new broker connection URL: tcp://MaPingdeMacBook-Pro.local:55469
[org.apache.activemq.transport.failover.FailoverTransport] : Successfully connected to tcp://MaPingdeMacBook-Pro.local:55469
[org.fusesource.mq.ProducerThread] : Sent: test message: 0
[org.fusesource.mq.ProducerThread] : Sent: test message: 1
[org.fusesource.mq.ProducerThread] : Sent: test message: 2
[org.fusesource.mq.ProducerThread] : Sent: test message: 3
[org.fusesource.mq.ProducerThread] : Sent: test message: 4
[org.fusesource.mq.ProducerThread] : Sent: test message: 5
[org.fusesource.mq.ProducerThread] : Sent: test message: 6
[org.fusesource.mq.ProducerThread] : Sent: test message: 7
[org.fusesource.mq.ProducerThread] : Sent: test message: 8
[org.fusesource.mq.ProducerThread] : Sent: test message: 9
[org.fusesource.mq.ProducerThread] : Producer thread finished
Produced: 10
[org.fusesource.mq.ActiveMQService] : Closed JMS connection
[org.fusesource.fabric.zookeeper.internal.AbstractZKClient] : StateChangeDispatcher terminated.
[org.apache.zookeeper.ZooKeeper[] : Session: 0x150656962ea0003 closed
org.apache.zookeeper.ClientCnxn] : EventThread shut down
[org.apache.activemq.transport.failover.FailoverTransport] : Transport (tcp://192.168.56.1:55469) failed, reason:  java.io.EOFException, attempting to automatically reconnect
[org.apache.activemq.transport.failover.FailoverTransport] : Successfully reconnected to tcp://MaPingdeMacBook-Pro.local:55469

(3)查看fabric集群情况

fabric:cluster-list
输出如下:
[cluster]                      [masters]                      [slaves]                       [services]
stats/default                                                                               
fusemq/default                                                                              
   tolerant                    broker1                        broker2                        tcp://MaPingdeMacBook-Pro.local:55469

(4)生产者,增加发送消息数量以及发送间隔
java -jar mq-client.jar producer --brokerUrl discovery:fabric:default --user admin --password admin --destination queue://summit.test --count 1000 -—sleep 1000

在此期间,启动/停止 container:fabric:container-{start,stop} <container name>

fabric:container-stop broker1
观察fabric集群的变化:fabric:cluster-list
fabric:container-start broker1
观察fabric集群的变化:fabric:cluster-list
fabric:container-stop broker2
观察fabric集群的变化:fabric:cluster-list
fabric:container-start broker2
观察fabric集群的变化:fabric:cluster-list

没有评论: