activemq持久化


默认使用kahadb:
<persistenceAdapter>
    <kahaDB directory="${activemq.data}/kahadb"/>
</persistenceAdapter>

设置为持久化,当消息中间件重启不会导致消息丢失
messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);


配置jdbc连接mysql:
cd conf
vi activemq.xml
找到kahadb的配置,注释掉:
<!--
<persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
</persistenceAdapter>
-->

配置mysql:
<persistenceAdapter>
            <jdbcPersistenceAdapter dataSource="#mysqlDB"/>
</persistenceAdapter>

在</broker>元素后添加:
<bean id="mysqlDB" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/activemq?relaxAutoCommit=true"/>
    <property name="username" value="root"/>
    <property name="password" value="123456"/>
    <property name="poolPreparedStatements" value="true"/>
</bean>

添加mysql驱动包到lib下

启动activemq,发现activemq数据库中多了三张表


你可能感兴趣的:(activemq持久化)