ActiveMQ 消息持久化到Mysql數據庫

1、下載ActiveMQ

版本:ActiveMQ 5.15.3 Releasehtml

地址:http://activemq.apache.org/download.htmljava

2、運行ActiveMQ

一、解壓apache-activemq-5.15.3-bin.zipmysql

二、執行\bin\win64\activemq.bat腳本便可啓動AMQweb

3、修改配置文件持久化到Mysql數據庫

文件路徑:\conf\activemq.xmlsql

 1 <!--
 2     Configure message persistence for the broker. The default persistence
 3     mechanism is the KahaDB store (identified by the kahaDB tag).
 4     For more information, see:
 5 
 6     http://activemq.apache.org/persistence.html
 7 -->
 8 <persistenceAdapter>
 9     <!--<kahaDB directory="${activemq.data}/kahadb"/>-->
10     <jdbcPersistenceAdapter dataSource="#mysql-ds"/>
11 </persistenceAdapter>
 1 <bean id="mysql-ds" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
 2     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
 3     <property name="url" value="jdbc:mysql://localhost:3306/db_activemq?relaxAutoCommit=true"/>
 4     <property name="username" value="root"/>
 5     <property name="password" value="root"/>
 6     <property name="poolPreparedStatements" value="true"/>
 7 </bean>
 8 
 9 <!--
10     Enable web consoles, REST and Ajax APIs and demos
11     The web consoles requires by default login, you can disable this in the jetty.xml file
12 
13     Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
14 -->
15 <import resource="jetty.xml"/>

4、引入Mysql包

複製mysql-connector-java-5.1.45.jar包到\lib\目錄下數據庫

5、從新運行AMQ,數據庫自動生成3張表

activemq_acks:用於存儲訂閱關係。若是是持久化Topic,訂閱者和服務器的訂閱關係在這個表保存apache

activemq_lock:在集羣環境中才有用,只有一個Broker能夠得到消息,稱爲Master Broker服務器

activemq_msgs:用於存儲消息,Queue和Topic都存儲在這個表中ide

相關文章
相關標籤/搜索