举例说明:
假设有 3 个 broker 节点,分别是61616,61618, 61620,其中 61616 和 61618 组成主、从节点,而 61616(或61618)和 61620 构成集群。
61616 和 61618 使用 jdbc 持久化,61620 使用 kahaDB。

这样混合配置:能更好地理解主从和集群的区别,61616 和 61618 在同一时刻只有一个 broker 提供服务,而集群是同时在提供服务,消息在集群的节点之间流转。

61616 配置:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd"> <broker useJmx="false" brokerName="jdbcBroker61616" xmlns="http://activemq.apache.org/schema/core">
<persistenceAdapter>
<jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#mysql-ds"/>
</persistenceAdapter> <networkConnectors>
<networkConnector uri="multicast://default"
dynamicOnly="true"
networkTTL="3"
prefetchSize="1"
decreaseNetworkConsumerPriority="true" />
</networkConnectors> <transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616" discoveryUri="multicast://default"/>
</transportConnectors>
</broker> <!-- MySql DataSource Sample Setup -->
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.40.8:3306/db_zhang?relaxAutoCommit=true"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="maxActive" value="200"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
</beans>

61618 配置:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd"> <broker useJmx="false" brokerName="jdbcBroker61618" xmlns="http://activemq.apache.org/schema/core">
<persistenceAdapter>
<jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#mysql-ds"/>
</persistenceAdapter>
<networkConnectors>
<networkConnector uri="multicast://default"
dynamicOnly="true"
networkTTL="3"
prefetchSize="1"
decreaseNetworkConsumerPriority="true" />
</networkConnectors> <transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61618" discoveryUri="multicast://default"/>
</transportConnectors>
</broker> <!-- MySql DataSource Sample Setup -->
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.40.8:3306/db_zhang?relaxAutoCommit=true"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="maxActive" value="200"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
</beans>

61620 配置:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:mq.properties"/>
</bean> <broker xmlns="http://activemq.apache.org/schema/core" brokerName="dynamic-broker2" dataDirectory="${activemq.base}/data"> <!-- Destination specific policies using destination names or wildcards -->
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="20mb">
<deadLetterStrategy>
<individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true" />
</deadLetterStrategy>
</policyEntry>
<policyEntry topic=">" producerFlowControl="true" memoryLimit="20mb">
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy> <!-- Use the following to configure how ActiveMQ is exposed in JMX -->
<managementContext>
<managementContext createConnector="true" connectorPort="1100"/>
</managementContext> <!--
Configure network connector to use multicast protocol
For more information, see http://activemq.apache.org/multicast-transport-reference.html
-->
<networkConnectors>
<networkConnector uri="multicast://default"
dynamicOnly="true"
networkTTL="3"
prefetchSize="1"
decreaseNetworkConsumerPriority="true" />
</networkConnectors> <persistenceAdapter>
<kahaDB directory="${activemq.base}/data/dynamic-broker2/kahadb" />
</persistenceAdapter> <!-- The maximum amount of space the broker will use before slowing down producers -->
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="20 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="1 gb" name="foo"/>
</storeUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage> <!--
The transport connectors ActiveMQ will listen to
Configure discovery URI to use multicast protocol
-->
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61620" discoveryUri="multicast://default" />
</transportConnectors> </broker>
</beans>

其中一个 producer 配置:

new ActiveMQConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61618)");

其中一个 consumer 配置:

new ActiveMQConnectionFactory("tcp://localhost:61620");

producer 往(61616主,61618从)发送消息,consumer 可以从 61620 获取消息。当 61616 下线后,61618 会成为主,并和 61620 构成集群。

ActiveMQ 集群和主从的更多相关文章

  1. ActiveMQ(七)_伪集群和主从高可用使用

      一.本文目的         介绍如何在同一台虚拟机上搭建高可用的Activemq服务,集群数量包含3个Activemq,当Activemq可用数>=2时,整个集群可用.         本 ...

  2. ActiveMQ(七)_伪集群和主从高可用使用(转)

    本文转自: https://www.cnblogs.com/gossip/p/5977489.html 一.本文目的         介绍如何在同一台虚拟机上搭建高可用的Activemq服务,集群数量 ...

  3. 使用jmeter对ActiveMQ集群性能方案进行评估--转载

    原文地址:http://www.51testing.com/html/78/23978-143163.html 1.测试概要1.1 关于这篇文档中涉及的基于JMS的消息系统能为应用程序提供可靠的,高性 ...

  4. ActiveMQ集群整体认识

    出自:https://segmentfault.com/a/1190000014592517 前言 最终需要掌握 Replicated LevelDB Store部署方式,这种部署方式是基于ZooKe ...

  5. 消息队列--ActiveMQ集群部署

    一.activeMQ主要的部署方式? 1,默认的单机部署(kahadb) activeMQ默认的存储单机模式,如果配置文件不做修改,则默认使用此模式.以本地的kahadb文件的方式进行存储,性能完全依 ...

  6. ActiveMQ集群应用

    ActiveMQ集群 ActiveMQ具有强大和灵活的集群功能,但在使用的过程中会发现很多的缺点,ActiveMQ的集群方式主要由两种:Master-Slave和Broker Cluster. 1.M ...

  7. 分布式ActiveMQ集群

    分布式ActiveMQ集群的部署配置细节: 官方资料:http://activemq.apache.org/clustering.html 基本上看这个就足够了,本文就不具体分析配置文件了. 1.Qu ...

  8. ActiveMQ集群(2)

    ActiveMQ具有强大和灵活的集群功能,但在使用的过程中会发现很多的缺点,ActiveMQ的集群方式主要有两种:Master-Slave和Broker Cluster. 1.Master-Slave ...

  9. 分布式ActiveMQ集群--转载

    原文地址:http://shensy.iteye.com/blog/1752529 回顾总结前一段时间学习的ActiveMQ分布式集群相关的知识,分享出来希望对看到的人有所帮助. 一.分布式Activ ...

随机推荐

  1. _itemmod_add

    命令._add items XXX 为目标添加一组物品 `comment`  备注 `categoryId` 组ID `entry` 物品entry `count`数量

  2. 【BZOJ】3214: [Zjoi2013]丽洁体

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3214 字符串长度最大不超过$5$直接$HASH$起来 首先在$T$中考虑找到最前的一个包含 ...

  3. hdu 2034 改革春风吹满地 多边形面积

    改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem ...

  4. JDBC Connection Configuration

    如果在Jmeter 中想用到连接数据库的功能,必须下载jar包,常见的关系型数据库jar包见以下共享链接 链接:https://pan.baidu.com/s/1t-k9RW141lw0j_QSw53 ...

  5. 封装sqlhelper【一】

    控件信息展示: //定义调用数据库类文件 namespace SqlHelper { public class TblClass { public int classId { get; set; } ...

  6. leecode第二十题(有效的括号)

    class Solution { public: bool isValid(string s) { ,end=s.size()-; )//万万没想到,他把空字符串当成true了 return true ...

  7. Vuex结合 async/await 优雅的管理接口请求

    先看看 async/await 的语法 async 函数返回一个 Promise 对象 async 函数内部 return 返回的值.会成为 then 方法回调函数的参数. 1 2 3 4 async ...

  8. ArcFace 2.0 Demo [C++]

    环境: win10(10.0.16299.0)+ VS2017 sdk版本:ArcFace v2.0 OPENCV3.43版本 x64平台Debug.Release配置都已通过编译 下载地址:http ...

  9. SuperMap 二维地图和三维场景弹窗窗口大小控制

    注:此处所说的弹窗窗口,主要指的是那些弹窗窗口中嵌入iframe,包含信息页面的窗口大小控制. 1.首先来了解下 SuperMap 示例中的处理方案 二维的处理方式 //初始化Anchored类 po ...

  10. Unity --- 纹理压缩基本知识点

    1.Unity支持的压缩格式的分类,这里主要指Android平台和IOS平台: DXT格式 --- Nvidia Tegra(图睿)提供ETC  --- 安卓原生支持的,OPNEGL2.0都支持,ET ...