August 20, 2013

Configure ActiveMQ 5.8.0 to use MySQL as Persistence Mechanism

Introduction

In this blog I will show you how to change, the default persistence mechanism in Apache ActiveMQ 5.8.0 from KahaDB to instead use a RDBMS. And here I will use MySQL 5, but ActiveMQ supports most of the major vendor of RDBMS.

Install MySQL JDBC Driver

Download driver from maven central repo:
http://search.maven.org/#artifactdetails%7Cmysql%7Cmysql-connector-java%7C5.1.19%7Cjar.

Copy to $ACTIVEMQ_HOME/lib/optional/.

Create ActiveMQ database

Log into mysql and create ActiveMQ database.

Configure MySQL as persistence storage

Open the ActiveMQ configuration, $ACTIVEMQ_HOME/conf/activemq.xml, and add mysql datasource, comment/remove the default KahaDB and finally add the RDBMS persistence adapter.

Test

Now we are ready to test the installation. Restart activemq and check the activemq log for errors, $ACTIVEMQ_HOME/data/activemq.log.

You can also open the activemq web console, to verify that things are working:
URL: http://localhost:8161/admin/
Username: admin
Password: admin

Now lets really test the installation from the activemq web console you can send message. From the web console click Send and choose to send a text message to a new queue.

Afterwards we can check that the message is sent to the queue, by clicking on Queue and our new queue foo.bar. And there see your text message.

You could also verify that the message is really persistent in MySQL by querying your database.

2 comments:

Anonymous said...

nice explanation :)

Karthik said...

Can I configure multiple mysql datasource for different queues within the same broker? I mean in Kaha we have that multiple persistence adapter. I want a similar functionality with MySql as my persistence store.