环境:OS X EI Capitan 10.11.3 + ActiveMQ 5.13.0
4个Broker,Broker1/Broker2 组成 Master/Slave,Broker3/Broker4 组成 Master/Slave,Broker1(Master)/Broker2(Slave)和 Broker3(Master)/Broker4(Slave)组成 Broker 集群。
mkdir activemq-cluster
cd activemq-cluster
cp -r ../apache-activemq-5.13.0 activemq-node1
cp -r ../apache-activemq-5.13.0 activemq-node2
cp -r ../apache-activemq-5.13.0 activemq-node3
cp -r ../apache-activemq-5.13.0 activemq-node4
1. Broker1 配置
(1)activemq-broker1-masterslave.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker1” dataDirectory="${activemq.data}">
<networkConnectors>
<networkConnector
name="T:broker1->broker3"
uri="masterslave:(tcp://localhost:61619,tcp://localhost:61620)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker1->broker3"
uri="masterslave:(tcp://localhost:61619,tcp://localhost:61620)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="/tmp/kahadb1"/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61617?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!--
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-->
</transportConnectors>
(2)jetty.xml
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8162"/>
</bean>
2. Broker2 配置
(1)activemq-broker2-masterslave.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker2" dataDirectory="${activemq.data}">
<networkConnectors>
<networkConnector
name="T:broker2->broker3"
uri="masterslave:(tcp://localhost:61619,tcp://localhost:61620)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker2->broker3"
uri="masterslave:(tcp://localhost:61619,tcp://localhost:61620)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="/tmp/kahadb1"/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61618?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!--
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-->
</transportConnectors>
(2)jetty.xml
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8163"/>
</bean>
3. Broker3 配置
(1)activemq-broker3-masterslave.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker3" dataDirectory="${activemq.data}">
<networkConnectors>
<networkConnector
name="T:broker3->broker1"
uri="masterslave:(tcp://localhost:61617,tcp://localhost:61618)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker3->broker1"
uri="masterslave:(tcp://localhost:61617,tcp://localhost:61618)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="/tmp/kahadb2"/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61619?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!--
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-->
</transportConnectors>
(2)jetty.xml
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8164"/>
</bean>
3. Broker4 配置
(1)activemq-broker4-masterslave.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker4" dataDirectory="${activemq.data}">
<networkConnectors>
<networkConnector
name="T:broker4->broker1"
uri="masterslave:(tcp://localhost:61617,tcp://localhost:61618)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker4->broker1"
uri="masterslave:(tcp://localhost:61617,tcp://localhost:61618)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="/tmp/kahadb2"/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61620?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!--
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-->
</transportConnectors>
(2)jetty.xml
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8165"/>
</bean>
4. 启动
(1)./activemq-node1/bin/activemq start xbean:activemq-broker1-masterslave.xml
(2)./activemq-node2/bin/activemq start xbean:activemq-broker2-masterslave.xml
(3)./activemq-node3/bin/activemq start xbean:activemq-broker3-masterslave.xml
(4)./activemq-node4/bin/activemq start xbean:activemq-broker4-masterslave.xml
5. 客户端
(1)Producer:"failover:(tcp://127.0.0.1:61617,tcp://127.0.0.1:61618)"
(2)Consumer:"failover:(tcp://127.0.0.1:61619,tcp://127.0.0.1:61620)"
参考文献:
1. https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.1/html/Fault_Tolerant_Messaging/files/FMQFaultTolNetwork.html
2. http://www.fwqtg.net/activemq%E5%AE%9E%E7%8E%B0%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%AB%98%E5%8F%AF%E7%94%A8%E9%83%A8%E7%BD%B2%E6%96%B9%E6%A1%88.html
3. http://tmielke.blogspot.com/2011/09/activemq-network-bridge-to-masterslave.html
4个Broker,Broker1/Broker2 组成 Master/Slave,Broker3/Broker4 组成 Master/Slave,Broker1(Master)/Broker2(Slave)和 Broker3(Master)/Broker4(Slave)组成 Broker 集群。
mkdir activemq-cluster
cd activemq-cluster
cp -r ../apache-activemq-5.13.0 activemq-node1
cp -r ../apache-activemq-5.13.0 activemq-node2
cp -r ../apache-activemq-5.13.0 activemq-node3
cp -r ../apache-activemq-5.13.0 activemq-node4
1. Broker1 配置
(1)activemq-broker1-masterslave.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker1” dataDirectory="${activemq.data}">
<networkConnectors>
<networkConnector
name="T:broker1->broker3"
uri="masterslave:(tcp://localhost:61619,tcp://localhost:61620)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker1->broker3"
uri="masterslave:(tcp://localhost:61619,tcp://localhost:61620)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="/tmp/kahadb1"/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61617?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!--
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-->
</transportConnectors>
(2)jetty.xml
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8162"/>
</bean>
2. Broker2 配置
(1)activemq-broker2-masterslave.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker2" dataDirectory="${activemq.data}">
<networkConnectors>
<networkConnector
name="T:broker2->broker3"
uri="masterslave:(tcp://localhost:61619,tcp://localhost:61620)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker2->broker3"
uri="masterslave:(tcp://localhost:61619,tcp://localhost:61620)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="/tmp/kahadb1"/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61618?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!--
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-->
</transportConnectors>
(2)jetty.xml
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8163"/>
</bean>
3. Broker3 配置
(1)activemq-broker3-masterslave.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker3" dataDirectory="${activemq.data}">
<networkConnectors>
<networkConnector
name="T:broker3->broker1"
uri="masterslave:(tcp://localhost:61617,tcp://localhost:61618)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker3->broker1"
uri="masterslave:(tcp://localhost:61617,tcp://localhost:61618)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="/tmp/kahadb2"/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61619?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!--
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-->
</transportConnectors>
(2)jetty.xml
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8164"/>
</bean>
3. Broker4 配置
(1)activemq-broker4-masterslave.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker4" dataDirectory="${activemq.data}">
<networkConnectors>
<networkConnector
name="T:broker4->broker1"
uri="masterslave:(tcp://localhost:61617,tcp://localhost:61618)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<queue physicalName=">" />
</excludedDestinations>
</networkConnector>
<networkConnector
name="Q:broker4->broker1"
uri="masterslave:(tcp://localhost:61617,tcp://localhost:61618)"
duplex="false"
decreaseNetworkConsumerPriority="true"
networkTTL="2"
dynamicOnly="true">
<excludedDestinations>
<topic physicalName=">" />
</excludedDestinations>
</networkConnector>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="/tmp/kahadb2"/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61620?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!--
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-->
</transportConnectors>
(2)jetty.xml
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8165"/>
</bean>
4. 启动
(1)./activemq-node1/bin/activemq start xbean:activemq-broker1-masterslave.xml
(2)./activemq-node2/bin/activemq start xbean:activemq-broker2-masterslave.xml
(3)./activemq-node3/bin/activemq start xbean:activemq-broker3-masterslave.xml
(4)./activemq-node4/bin/activemq start xbean:activemq-broker4-masterslave.xml
5. 客户端
(1)Producer:"failover:(tcp://127.0.0.1:61617,tcp://127.0.0.1:61618)"
(2)Consumer:"failover:(tcp://127.0.0.1:61619,tcp://127.0.0.1:61620)"
参考文献:
1. https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.1/html/Fault_Tolerant_Messaging/files/FMQFaultTolNetwork.html
2. http://www.fwqtg.net/activemq%E5%AE%9E%E7%8E%B0%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%AB%98%E5%8F%AF%E7%94%A8%E9%83%A8%E7%BD%B2%E6%96%B9%E6%A1%88.html
3. http://tmielke.blogspot.com/2011/09/activemq-network-bridge-to-masterslave.html
没有评论:
发表评论