Thursday, June 25, 2015

Configuring ActiveMQ to MySQL Database

Introduction...

Hi All,

By default, ActiveMQ broker uses KahaDB as the persistence message store. In the following post we will be configuring ActiveMQ to use a MySQL database.

Steps 1

Modify the "activemq.xml" file which is located at "<ACTIVEMQ_HOME>/conf/" folder. Here we have to add a bean which contains the connection details for the MySQL database and also have to indicate that we are gonna use MySQL as the message store.

Add the MySQL database connection information as below.

<beans .....>
    ......
    <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://localhost/activemq"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
        <property name="poolPreparedStatements" value="true"/>
    </bean>
    ......
</beans>

Remove the KahaDB message store and add the MySQL message store.

<beans .....>
    <broker .....>
        ......
        <persistenceAdapter>
            <jdbcPersistenceAdapter dataSource="#mysql-ds"/>
            <!-- <kahaDB directory="${activemq.data}/kahadb"/> -->
        </persistenceAdapter>
        ......
    </broker>
</beans>

Steps 2

Add the MySQL driver to "<ACTIVEMQ_HOME>/lib/optional/" folder

And thats all folks.

References...

[1] - http://activemq.apache.org/how-to-configure-a-new-database.html
[2] - http://activemq.2283324.n4.nabble.com/ActiveMQ-4-0-won-t-start-td2343357.html

No comments:

Post a Comment