2016年2月6日星期六

ActiveMQ_011:单机环境下配置三节点 Broker 集群

环境:OS X EI Capitan 10.11.3 + ActiveMQ 5.13.3

三个Broker,“首尾相接”,组成一个Broker “闭环”,无论Producer把消息发送到哪个Broker上,无论Consumer在哪个Broker上接收消息,都可以收到。

mkdir activemq-cluster
cd  activemq-cluster
cp -r ../apache-activemq-5.13.3 activemq-node1
cp -r ../apache-activemq-5.13.3 activemq-node2
cp -r ../apache-activemq-5.13.3 activemq-node3

1.  Broker1 配置
(1)activemq-broker1.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker1” dataDirectory="${activemq.data}">
       
    <networkConnectors>
        <networkConnector
                name="T:broker1->broker2"
                uri="static:(tcp://localhost:61618)"
                duplex="false"
                decreaseNetworkConsumerPriority="true"
                networkTTL="2"
                dynamicOnly="true">
                <excludedDestinations>
                    <queue physicalName=">" />
                </excludedDestinations>
            </networkConnector>
            <networkConnector
                name="Q:broker1->broker2"
                uri="static:(tcp://localhost:61618)"
                duplex="false"
                decreaseNetworkConsumerPriority="true"
                networkTTL="2"
                dynamicOnly="true">
                <excludedDestinations>
                    <topic physicalName=">" />
                </excludedDestinations>
            </networkConnector>
        </networkConnectors>

        <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="8162"/>
</bean>

2.  Broker2 配置
(1)activemq-broker2.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker2" dataDirectory="${activemq.data}">

        <networkConnectors>
            <networkConnector
                name="T:broker2->broker3"
                uri="static:(tcp://localhost:61619)"
                duplex="false"
                decreaseNetworkConsumerPriority="true"
                networkTTL="2"
                dynamicOnly="true">
                <excludedDestinations>
                    <queue physicalName=">" />
                </excludedDestinations>
            </networkConnector>
            <networkConnector
                name="Q:broker2->broker3"
                uri="static:(tcp://localhost:61619)"
                duplex="false"
                decreaseNetworkConsumerPriority="true"
                networkTTL="2"
                dynamicOnly="true">
                <excludedDestinations>
                    <topic physicalName=">" />
                </excludedDestinations>
            </networkConnector>
        </networkConnectors>

        <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.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker3" dataDirectory="${activemq.data}">

        <networkConnectors>
             <networkConnector
                name="T:broker3->broker1"
                uri="static:(tcp://localhost:61617)"
                duplex="false"
                decreaseNetworkConsumerPriority="true"
                networkTTL="2"
                dynamicOnly="true">
                <excludedDestinations>
                    <queue physicalName=">" />
                </excludedDestinations>
            </networkConnector>
            <networkConnector
                name="Q:broker3->broker1"
                uri="static:(tcp://localhost:61617)"
                duplex="false"
                decreaseNetworkConsumerPriority="true"
                networkTTL="2"
                dynamicOnly="true">
                <excludedDestinations>
                    <topic physicalName=">" />
                </excludedDestinations>
            </networkConnector>
        </networkConnectors>

        <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>

4. 启动
(1)./activemq-node1/bin/activemq start xbean:activemq-broker1.xml
(2)./activemq-node2/bin/activemq start xbean:activemq-broker2.xml
(3)./activemq-node3/bin/activemq start xbean:activemq-broker3.xml

5. 测试
(1)./activemq producer --brokerUrl tcp://localhost:61617 --user admin --password admin --destination queue://testQueue --messageSize 1024 --messageCount 1000 --parallelThreads 10
(2)./activemq consumer --brokerUrl tcp://localhost:61618 --user admin --password admin --destination queue://testQueue --messageCount 1000 --parallelThreads 10
(3)./activemq producer --brokerUrl tcp://localhost:61618 --user admin --password admin --destination queue://testQueue --messageSize 1024 --messageCount 1000 --parallelThreads 10
(4)./activemq consumer --brokerUrl tcp://localhost:61617 --user admin --password admin --destination queue://testQueue --messageCount 1000 --parallelThreads 10

参考文献:
1. http://www.huaishao8.com/config/activemq/178.html

没有评论: