Retrive embedded ActiveMQ messages

How can you get messages out of an embedded ActiveMQ kaha db?

Well this question came up this week in conversation at work after my colleagues had spent a fair few hours trying to achieve this goal. I always prefer the simplest option possible and thought, well why not just copy the kaha db into a fresh ActiveMQ installation and boot up the admin console? Unable to give this a go on Friday, I’ve just found the time to try it.

First of all I need a message on an embedded broker kaha db and since I use Mule a lot, this little demo will use Mule to put a fake message on a queue.

First we need a mule config file to take an inbound vm message and place it on an ActiveMQ queue.

<mule xmlns=""

    <jms:activemq-connector name="jmsConnector"
			persistentDelivery="true" />
    <vm:connector name="abc" />
    <flow name="dropMessageOnAMQ">
        <vm:inbound-endpoint address="vm://amq" exchange-pattern="one-way" connector-ref="abc" />
        <jms:outbound-endpoint queue="testQ" connector-ref="jmsConnector" exchange-pattern="one-way"  />

Next a very simple test class which puts a message on the vm


import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.mule.api.MuleException;
import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;
import org.mule.tck.FunctionalTestCase;

public class ActiveMQQueueLoaderMule extends FunctionalTestCase
    public void testAddMsgToQ() throws Exception
        MuleClient client = new MuleClient(muleContext);
        MuleMessage message = client.send("vm://amq?connector=abc", "hello me", null);

    protected String getConfigResources()
        return "mule-cfg.xml";

Run the test and a kaha db file will be created.


Copy the directory KahaDB into a fresh ActiveMQ installation, e.g.


Boot up ActiveMQ


Go into the Queues tab


Go into the message(s) in question and you’ll be able to see the data and use it if necessary


Please note this is not recommended for production use – it’s here for reference
The above does rely on persistence being specified otherwise the messages would be cleared when the application stops.
Where possible, a standalone ActiveMQ installation should be used separate from your application so you can access the queues, move messages around and have full fail over. Embedded is great for testing things during development but has limitations.