2015年10月14日星期三

AMQ_004:A-MQ 功能演示4:Networks Broker 负载均衡架构

环境:JBoss A-MQ 6.0.0

Master/Slave架构解决了容错和高可用问题,但是没有解决负载均衡和横向扩展性问题。

1. Networks Broker
两个Broker通过networks连接在一起,这两个Broker分别使用不同的persistence stores。
通过networks连接在一起的Broker,意味着它们之间可以为某个Desitination转发消息。
而客户端只需连接任意一个Broker即可。

(1)创建 A-MQ-East container,属于 a-mq-east 组,并且和 a-mq-west broker 以networks方式连接
fabric:mq-create --group a-mq-east --networks a-mq-west --networks-username admin --networks-password admin --create-container A-MQ-East a-mq-east-broker
输出如下:
MQ profile a-mq-east-broker ready
Successfully created container A-MQ-East
(2)创建 A-MQ-West container,属于 a-mq-west 组,并且和 a-mq-east broker 以networks方式连接
fabric:mq-create --group a-mq-west --networks a-mq-east --networks-username admin --networks-password admin --create-container A-MQ-West a-mq-west-broker
输出如下:
MQ profile a-mq-west-broker ready
Successfully created container A-MQ-West

以上两步创建了两个Containers:A-MQ-East、A-MQ-West,以及这两个Containers对应的两个Profiles:a-mq-east-broker、a-mq-west-broker。
每个 Container 运行一个内嵌的 ActiveMQ 实例,它们之间以networks方式连接在一起。

(3)生产者
java -jar mq-client.jar producer --brokerUrl discovery:fabric:a-mq-east --user admin --password admin --destination queue://summit.test --count 10
输出如下:
Using destination: queue://summit.test, on broker: discovery:fabric:a-mq-east
[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@72cf2e49
[org.apache.zookeeper.ClientCnxn] : Opening socket connection to server /127.0.0.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 localhost/127.0.0.1:2181, initiating session
[org.apache.zookeeper.ClientCnxn] : Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x150656962ea0009, negotiated timeout = 10000
[org.apache.activemq.transport.discovery.DiscoveryTransport] : Adding new broker connection URL: tcp://MaPingdeMacBook-Pro.local:55602
[org.apache.activemq.transport.failover.FailoverTransport] : Successfully connected to tcp://MaPingdeMacBook-Pro.local:55602
[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.activemq.transport.failover.FailoverTransport] : Transport (tcp://192.168.56.1:55602) failed, reason:  java.io.EOFException, attempting to automatically reconnect
[org.apache.zookeeper.ZooKeeper] : Session: 0x150656962ea0009 closed
[org.apache.zookeeper.ClientCnxn] : EventThread shut down
[org.apache.activemq.transport.failover.FailoverTransport] : Successfully reconnected to tcp://MaPingdeMacBook-Pro.local:55602

(4)消费者
java -jar mq-client.jar consumer --brokerUrl discovery:fabric:a-mq-west --user admin --password admin --destination queue://summit.test --count 10
输出如下:
Using destination: queue://summit.test, on broker: discovery:fabric:a-mq-west
[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@51a669d5
[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 = 0x150656962ea000a, negotiated timeout = 10000
[org.apache.activemq.transport.discovery.DiscoveryTransport] : Adding new broker connection URL: tcp://MaPingdeMacBook-Pro.local:55617
[org.apache.activemq.transport.failover.FailoverTransport] : Successfully connected to tcp://MaPingdeMacBook-Pro.local:55617
Waiting for: 10 messages
[org.fusesource.mq.ConsumerThread] : Received test message: 0
[org.fusesource.mq.ConsumerThread] : Received test message: 1
[org.fusesource.mq.ConsumerThread] : Received test message: 2
[org.fusesource.mq.ConsumerThread] : Received test message: 3
[org.fusesource.mq.ConsumerThread] : Received test message: 4
[org.fusesource.mq.ConsumerThread] : Received test message: 5
[org.fusesource.mq.ConsumerThread] : Received test message: 6
[org.fusesource.mq.ConsumerThread] : Received test message: 7
[org.fusesource.mq.ConsumerThread] : Received test message: 8
[org.fusesource.mq.ConsumerThread] : Received test message: 9
[org.fusesource.mq.ConsumerThread] : Consumer thread finished
Consumed: 10 messages
[org.fusesource.mq.ActiveMQService] : Closed JMS connection
[org.fusesource.fabric.zookeeper.internal.AbstractZKClient] : StateChangeDispatcher terminated.
[org.apache.activemq.transport.failover.FailoverTransport] : Transport (tcp://192.168.56.1:55617) failed, reason:  java.io.EOFException, attempting to automatically reconnect
[org.apache.zookeeper.ZooKeeper] : Session: 0x150656962ea000a closed
[org.apache.zookeeper.ClientCnxn] : EventThread shut down
[org.apache.activemq.transport.failover.FailoverTransport] : Successfully reconnected to tcp://MaPingdeMacBook-Pro.local:55617

小结:Producer 发送消息到 A-MQ-East broker,Consumer 从 A-MQ-West broker 上接收该消息。

没有评论: