activemq cluster masterslave 配置

Activemq集群主备简单配置,基于5.13.3


Master-slave 基于zk的方式

修改activemq.xml

<brokerxmlns="http://activemq.apache.org/schema/core" brokerName="<span style="color:#ff0000;">broker-a</span>"dataDirectory="${activemq.data}">

<replicatedLevelDB
               directory="activemq-data"
                replicas="3"
               bind="tcp://0.0.0.0:0"
                zkAddress="your address"
               zkPath="/activemq/leveldb-stores"
                hostname="localhost "
                sync=”local_disk”
/>
<transportConnector name="openwire"uri="tcp://${ip}:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>

${ip} 应该是机器的实际ip地址,使用127.0.0.1或者localhost,则导致client无法连接.

修改jetty.xml,修改端口号为不同的(e.g. 8161, 8161,8163)

 

然后启动

./activemq start (后台进程)

./activemq stop

 

基于上述配置,创建2个slave的目录,

brokerName一致才会认为是一个cluster,且至少有3个才会成功,否则无法选主,导致没有broker可以提供服务


测试master-slave:

Uri="failover:(tcp://ip1:61616,tcp://ip2:61617,tcp://ip3:61618)"

消息发送,默认到ip1上,查看ip1的admin后台,有消息(此时ip1为master)

停止ip1的服务,继续发送,查看ip2的admin后台,有新消息达到(此时ip2为master)

启动ip1的服务,可以看到变成slave



配置cluster:

和上面的配置类似,brokerName变成broker-b,tcp的端口进行变更

剩余其他的transportConnector,对应的端口号,每组broker可以一致,但是不同的broker要不同(我是同一台机器)

启动broker-a 和 broker-b

可以看到2个broker直接建立链接的log

 | Network connection between vm://broker-a#6 and tcp://{ip}:61716 (broker-b) has been established.


 INFO  | Network connection between vm://broker-b#0 and tcp://{ip}:61616 (broker-a) has been established.

最终broker-a的配置

<networkConnectors>
	<!-- 连接broker-b -->
    <networkConnector uri="masterslave:(tcp://${ip}:61716,tcp:// ${ip}:61717,tcp:// ${ip}:61718)"/>
 </networkConnectors>
        <persistenceAdapter>
           <replicatedLevelDB
                directory="activemq-data"
                replicas="3"
                bind="tcp://0.0.0.0:0"
                zkAddress="${ip}:2181"
                zkPath="/activemq/leveldb-stores"
                hostname="localhost"
                sync="local_disk"
                />
        </persistenceAdapter>

<transportConnectors>
            <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
			<!-- 示例用的tcp,每个机器的端口要不同-->
            <transportConnector name="openwire" uri="tcp://${hostIp}:61616?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>
broker-b的配置

<networkConnectors>
	<!-- 连接broker-a -->
    <networkConnector uri="masterslave:(tcp://${ip}:61616,tcp:// ${ip}:61617,tcp:// ${ip}:61618)"/>
 </networkConnectors>
        <persistenceAdapter>
           <replicatedLevelDB
                directory="activemq-data"
                replicas="3"
                bind="tcp://0.0.0.0:0"
                zkAddress="${ip}:2181"
                zkPath="/activemq/leveldb-stores"
                hostname="localhost"
                sync="local_disk"
                />
        </persistenceAdapter>

<transportConnectors>
            <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
			<!-- 示例用的tcp,每个机器的端口要不同-->
            <transportConnector name="openwire" uri="tcp://${hostIp}:61716?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>

测试cluster

Uri="failover:(tcp://ip1:61616,tcp://ip2:61617,tcp://ip3:61618,tcp://ip4:61716,tcp://ip5:61717,tcp://ip6:61718)"

1.启动Java的consumer client,看log连到了broker-a,即前3个ip的集群

从broker-a的后台给queue发消息(10个),client可以接收到

从broker-b的后台给queue发消息(5个),client也可以接收到(broker-a会从broker-b把消息拉过来)

此时broker-a的queue上有15个消息,broker-b上有5个消息

2.启动2个consumer,分别连到broker-a 和 broker-b,向不同的broker发消息,对应的consumer可以接收到,向某一个broker发多个消息,两个consumer均能收到消息

 

看log,urlList和上面的uri顺序是不一致的,然后按顺序连接

 

 

Reference
http://activemq.apache.org/clustering.html

http://activemq.apache.org/replicated-leveldb-store.html

http://activemq.apache.org/persistence.html

http://kevinboone.net/amqmasterslave.html 
https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.1/html/Fault_Tolerant_Messaging/files/FMQFaultTolNetwork.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值