activemq cluster masterslave 配置
2016-05-25 14:03
471 查看
Activemq集群主备简单配置,基于5.13.3
Master-slave 基于zk的方式
修改activemq.xml
${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的配置
测试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
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
相关文章推荐
- Openerp中的fields.related类型的懂得
- 设置系统状态栏样式分析
- jdk源码分析之HashMap
- 安卓动态调试七种武器之长生剑 - Smali Instrumentation
- Spark ML 基础:DataFrame、Dataset、feature
- 构建之法阅读笔记06
- iOS-如何写好一个UITableView
- Python基础之内置函数(一)
- [iCloud]iCloud学习笔记--APP内启用iCloud及CloudKit Dashboard介绍
- 一个zookeeper命令行工具——zoo_cmd
- hdu 1754(i hate it)
- jQuery中的each()详细介绍(推荐)
- 内存中常见异常值的解释(比如0xcccccccc、0xcdcdcdcd和 0xfeeefeee 异常值 )
- 自定义ViewGroup---点击控件时水波纹效果
- Ignatius and the Princess IV
- HttpSessionAttributeListener
- Java小程序:辗除法求两个正整数最大公约数和最小公倍数
- hihoCoder 1061 Beautiful String
- 正则表达式获取URL参数
- socket编程:简单UDP服务器/客户端编程