activemq是Apache一个重要的开源产品,对于queue的应用起到了很大的推动作用,当在实际的项目中应用时,通过queue传输的数据的安全性,是一个首要要考虑的问题,在activemq的配置中提供了三种mater/slave的备份方式:
一是内存备份,在系统停机后,原来的数据丢失,配置文件如下:
master broker的配置文件,没有任何特殊的地方,是一个标准的broker配置。
<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
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<broker brokerName="master" xmlns="http://activemq.apache.org/schema/core">
<transportConnectors>
<transportConnector uri="tcp://localhost:62001"/>
</transportConnectors>
</broker>
</beans>
slave broker的配置文件中,红色的部分很重要,表明和一个master组成一个备份的结构,在正常情况下,这个slave处于standby状态,当master出现问题是,slave转为工作状态。
<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
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<broker brokerName="slave" shutdownOnMasterFailure = "false" masterConnectorURI="tcp://localhost:62001" xmlns="http://activemq.apache.org/schema/core">
<managementContext >
<managementContext createConnector="true" connectorPort ="1098"/>
</managementContext>
<transportConnectors>
<transportConnector uri="tcp://localhost:62002"/>
</transportConnectors>
</broker>
</beans>
二、利用共享文件配置master/slave的结构:
1、在默认的情况下,activemq启动是利用文件作为持久化的存储,所以当两个broker在同一台服务器上启动,
都不配 persistenceAdapter的情况下,就是文件文件共享式的互备机制。
2、利用persistenceAdapter可以配置共享文件的位置,当broker启动在不同的服务器上时,
才能形成互备机制。
两个配置文件,除去transportationConnector不一致外,其他都相同:
<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
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<broker brokerName="shared" xmlns="http://activemq.apache.org/schema/core">
<!--
在默认的情况下,activemq启动是利用文件作为持久化的存储,所以当两个broker在同一台服务器上启动,
都不配 persistenceAdapter的情况下,就是文件文件共享式的互备机制。
利用persistenceAdapter可以配置共享文件的位置,当broker启动在不同的服务器上时,
才能形成互备机制。
-->
<persistenceAdapter>
<journaledJDBC dataDirectory="/sharedFileSystem/broker"/>
</persistenceAdapter>
<transportConnectors>
<transportConnector uri="tcp://localhost:62001"/>
</transportConnectors>
</broker>
</beans>
三、利用数据库进行备份和文件的备份机制基本相同。