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:
- I updated the Spring configuration by updating the beans tag name space specification.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:amq="http://activemq.org/config/1.0" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://activemq.org/config/1.0 http://activemq.apache.org/snapshot-schema/activemq-core-5.0-SNAPSHOT.xsd"> ... <beans> - Add the configuration to create the embedded broker
<!-- lets create an embedded ActiveMQ Broker --> <amq:broker useJmx="false" persistent="false"> <amq:transportConnectors> <amq:transportConnector uri="tcp://localhost:0" /> </amq:transportConnectors> </amq:broker> - Now when you start Tomcat, you’ll see the following error message:
SEVERE: Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate NamespaceHandler for namespace [http://activemq.org/config/1.0] Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]To fix this issue, you must add
xbean-spring-3.0.jarto the lib folder of your webapp. This jar is in the.../lib/optional/folder of your ActiveMQ release. - 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 activemq.apache.org was unreachable and I had to copy the xsd file to my web server for any of this work).
