Archive for the ‘ActiveMQ’ Category

ActiveMQ activemq-data and data folders

January 28, 2008

When you start an ActiveMQ broker, it creates two “data” folders in its home directory called activemq-data and data. The former is used for temporary storage and the data folder is where it keeps its log — activemq.log — file.

ActiveMQ 5.0 JDBC Master/Slave requires InnoDB table

January 26, 2008

The slave ActiveMQ broker in a JDBC Master/Slave set up requires that the lock table be of the type InnoDB. MyISAM table can lead to real problems including effectively brining your database down where the only way out would be to kill the slave or reboot your database. For a description of the bug, see here. Basically, you must ensure that the default table creation for your mysql is set to InnoDB, or after you start ActiveMQ, alter its tables in the database (your other options is to modify the ActiveMQ class and rebuild ActiveMQ).

By default MySQL will create MyISAM based tables. You can alter a table type so that its storage engine is set to InnoDB. For ActiveMQ, you’ll need to alter the three tables that it creates:


ActiveMQ 5.0 still leaks Files

January 26, 2008

When you run slave versions of ActiveMQ broker in a journal filesystem Master/Slave setup, you better watch out for file handle leaks. This problem was reported a long time ago (in 4.1 release) and it still has not been fixed in the latest 5.0 release of AMQ. So the only way to avoid this is to manually apply the patch and rebuild activeio-core library and activemq itself.

ActiveMQ issue tracker is a good place to check the state of open bugs.

Interesting interview with the ActiveMQ lead.

How to use Eclipse on ActiveMQ

January 26, 2008

ActiveMQ projectsSee ActiveMQ site to get started. You’ll need subversion, maven and of course eclipse before you begin. By default the maven repository is in your home directory, e.g., ~/.m2/repository.

Here are the steps:

svn co activemq
cd activemq
mvn eclipse:eclipse

Now fire up Eclipse and import the root folder of the ActiveMQ source folder. This will create about a dozen projects. But the Eclipse build will fail due to the variable M2_REPO not being defined. Just get the Properties of one of these projects, go to the Java Build Path and Add a Variable. Define this variable to be the location of your maven repository. After you do this all of the errors will disappear, you’ll still get 1700 or so warnings. But you know that in a lot of projects warnings are intended to be ignored.

You’ll also need to get the activeio sources. 

svn co activeio

You’ll need to import this project to Eclipse too (activeio/activeio-core).

ActiveMQ Embedded Broker

November 7, 2007

You can run ActiveMQ brokers in your Spring based servlets. Embedding ActiveMQ should make the deployment easier, since the embedded broker is running in the JVM of Tomcat, and you wont have to monitor a second set of JMV clusters simply to be able to use JMS in your application.

I tried to get embedded broker to work using the relatively scant ActiveMQ documentation on this topic. Here is what I did:

  1. I updated the Spring configuration by updating the beans tag name space specification.
    <beans xmlns=""
  2. Add the configuration to create the embedded broker
      <!--  lets create an embedded ActiveMQ Broker -->
      <amq:broker useJmx="false" persistent="false">
          <amq:transportConnector uri="tcp://localhost:0" />
  3. Now when you start Tomcat, you’ll see the following error message:
    SEVERE: Context initialization failed
      Configuration problem: Unable to locate NamespaceHandler for namespace []
    Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]

    To fix this issue, you must add xbean-spring-3.0.jar to the lib folder of your webapp. This jar is in the .../lib/optional/ folder of your ActiveMQ release.

  4. Now the code compiles and the servlet does start, but there were other issues, the number of threads under eclipse kept changing rapidly and I still needed to figure out what other configuration settings I need to pass to ActiveMQ. I’ll tackle this part later… (last night when I was trying this was unreachable and I had to copy the xsd file to my web server for any of this work).

Spring with ActiveMQ

July 3, 2007

Spring provides an abstraction for dealing with JMS. Specifically for adding and removing messages to a JMS queue and for browsing a queue. I found the documentation for removing messages from a queue, i.e., consuming messages in the context of a servlet to be somewhat scant. Here is what I had to do configure Spring to send and consume messages. (more…)

How to get the geronimo spec sources

June 27, 2007

ActiveMQ uses the Apache Geronimo’s implementation of javax.jms.* package. For debugging, it is nice to have the sources. Hunting for the sources of geronimo-jms_1.1_spec-1.0.jar took a while and deserves to be documented. The confusing part is that the sources of “specs” are not part of the subversion trunk, but instead they are part of the 1.1 branch. The geronimo site does explain why they designed it this way. Any how, here is how you can get the entire sources for the specs: jms, mail, …

svn co


ActiveMQ Master/Slave Setup

June 24, 2007

Active MQ Master-SlaveActive MQ offers three variations on how you configure your master/slave nodes. Here I assume a Shared Filesystem Master/Slave. This configuration provides the optimum performance and reliability. You can terminate the master, and then one of the slaves will become the master (almost immediately — within 10 seconds).

You can test a master/slave setup on your computer by multi-homing your network card and thus run multiple instances of the activemq broker. For each node, you’ll need to create a separate configuration file (copy the ./conf/activemq.xml file and use it as a template. The name of the broker must be set to the IP address or the DNS name of the master or one of slaves.

  <broker xmlns=""

    <!-- The transport connectors ActiveMQ will listen to -->
       <transportConnector name="openwire" uri="tcp://" />
       <transportConnector name="ssl"     uri="ssl://"/>
       <transportConnector name="stomp"   uri="stomp://"/>
       <transportConnector name="xmpp"    uri="xmpp://"/>

    <!-- The store and forward broker networks ActiveMQ will listen to -->
      <networkConnector name="HA Queue"
          uri="static://(tcp://,tcp://" />


Change the IP address (and the broker name) for each node in the node’s configuration file.

I created a screencast to help remind me of the steps. In this screencast, you’ll see that I start a master and then the slave. The salve is just waiting on lock on the journal file-system. I then terminate the master and you’ll see that the slave now becomes the master. Finally I restart the former master and this time it become a slave.

Configure ActiveMQ with MySQL

June 23, 2007

  1. You’ll need to create an activemq configuration file, call it my-activemq.xml say. (Just copy ./conf/activemq.xml and modify it as described here.
  2. Uncomment & update the persistenceAdapter:
            <journaledJDBC journalLogFiles="5"
  3. Uncomment the mysql-ds datasource (update the MySQL username/password):
      <bean id="mysql-ds"
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url"
        <property name="username" value="root"/>
        <property name="password" value=""/>
        <property name="poolPreparedStatements" value="true"/>
  4. Get the MySQL Java Connector (aka the driver). Add the connector jar file
    to the activemq‘s classpath (just copy this jar to the activemq‘s lib/optional folder. Launch the MySQL command line program and create a database for ActiveMQ to use: create database activemq;
  5. You can now start the broker using the xbean option:
    ./bin/activemq xbean:./conf/my-activemq.xml
  6. The broker (aka JMS server) should start without a problem. You can verify that it using the database. Check the activemq database and you’ll see that 3 new tables have been created:
    mysql> use activemq; show tables;
    Database changed
    | Tables_in_activemq |
    | ACTIVEMQ_ACKS      |
    | ACTIVEMQ_LOCK      |
    | activemq_msgs      |
    3 rows in set (0.00 sec)

    Also visit the ActiveMQ’s admin console on http://localhost:8161/ to make sure that all is well.

How to build ActiveMQ

June 23, 2007

ActiveMQ Admin ConsoleBuilding ActiveMQ requires a certain minimal level of familiarity with maven. You can build ActiveMQ without a hitch, but once you do, where do you find it? Where does ActiveMQ gets installed. The apache ActiveMQ documentation simply does not bother to mention what the maven build will actually create. Here are the steps that I followed: