ActiveMQ Embedded Broker

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).

8 Responses to “ActiveMQ Embedded Broker”

  1. Ferry Says:

    Could you send me the sample code on how to run ActiveMQ embedded broker to my mail ?
    The document is not very clear, as there’s no explanation on the XML.
    If we want to use VM transport should the :

    –> changed to “vm://localhost”

  2. sj Says:

    Hi, I’ve not used the VM transport. I’ve so far always used the tcp transport. I gave up trying to get the embedded broker to work. When I get more time I’ll have another go at it.

  3. Ak Says:

    Hi Sj,

    Had other problems trying to embed the broker into a webapplication.
    I tried fixing one error after other by making modifications to the activemq.xml file but they never seem to end.
    As per my understanding, I believe that embedding a broker means- well- making it run as part of your container. is that right? I’ve poured *all* the jars in the activemq/lib dir to the lib directory of my webapp. But I get a plethora of problems. Currently, I’ve got problems configuring the keystore and cert stuff that were available previously in the conf directory. How do I go about setting these things in my embedded broker? This broker thing almost got me broke.

    any help? Feel free to email back. I need all the help I can get. πŸ™‚

  4. Ak Says:

    And another thing, I just forgot to tell you- this is what I did-

  5. Ak Says:

    BTW, I tried out your code, it throws an exception-
    amq:broker not found … some exception related to not finding the element declaration.
    I changed the
    in the schemaLocation attribute of the xml file.

  6. sj Says:

    Yes this is also my understanding of the embedded broker. On paper it lets you run AMQ with your servlet container and this way you don’t have to manage another JVM (the one for AMQ). As I mentioned in my post, I was attracted by the promise of the embedded broker, but I couldn’t get it to work in my 1st attempt and for now I’ve given up.

    If you do get it to work, please let us know πŸ™‚

  7. Captain, we’re experiencing a configuration problem… « Our Craft Says:

    […] An entry in the note19 blog gave me the idea to check to make sure my project includes the AOP portion of the Spring libraries in its dependencies… so I ended up adding both spring-aop and spring-aspects to my pom file. […]

  8. henry Says:

    Hi guys,
    I am trying to make this embedded broker to work…I don’t get any error messages in the deployment phase of tomcat (I am using Tomcat 6).
    I am trying to make a javascript send a message to a queue.
    It does not work…the error console of firefox says “amq is not defined”
    I can’t find out the reaon behind that…when I deploy Tomcat it says that there is a connector listening at tcp://localhost:61616 .
    Any one had this error before?

    Thanks to all.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: