Auto-Start Apache ActiveMQ 5.4.2 with Apache Tomcat 6.0.30
Posted by sushantnayak on January 29, 2011
I could not get any helpful information, how to auto-start ActiveMQ broker from Tomcat. And thus, I finally, after 4 fruitful hours, configured.
This is my valuable contribution to open-source community.
Step 1
Install ActiveMQ and Tomcat from following places,
http://activemq.apache.org/activemq-542-release.html and
http://apache.ziply.com/tomcat/tomcat-6/v6.0.30/bin/apache-tomcat-6.0.30.zip
Also download activemq web console for autostarting activemq instance from tomcat.
http://repo1.maven.org/maven2/org/apache/activemq/activemq-web-console/5.4.2/
Step 2
Copy “activemq-all-5.4.2.jar” from activemq\lib to tomcat\lib
Copy “activemq-web-console-5.4.2.war” inside tomcat webapps
Step 3
Configure %CATALINA_HOME%\bin\catalina.bat or .sh by adding the following line
set JAVA_OPTS=”-Dwebconsole.jms.url=tcp://localhost:61616 -Dwebconsole.type=properties”
Step 4
If you have already set the java, catalina and activemq path variable then you can start the tomcat service from the console as,
C:\>startup
Step 5
Enter the following on the browser address bar,
Tomcat
http://localhost:8080/
ActiveMQ Web Console
http://localhost:8080/activemq-web-console-5.4.2/
If someone needs further information, I’m happy to help.
Open-Source community rocks !!!
AdictoaAprender said
Hello, Iam a beginner with JMS, I’m trying to make a Hello World App, a chat. I followed all directions for install activemq, and included a new topic in the configuration page.
But I have a problem getting the JNDI.
I am going to include the sourse and error text.
Sourse:
———————————————————–
public class ClienteJMSChat implements javax.jms.MessageListener {
private static final String CONTEXT_FACTORY =
“org.exolab.jms.jndi.InitialContextFactory”;
/**:::: I think the problem here could be ::::::::::::::::::*/
protected static final String PROVIDER_URL = “tcp://localhost:61616″;
/** this is the name of the topic created by me */
protected static final String TOPIC_CONNECTION_FACTORY =”Friki”;
public void initialize(String topico, String usuario, String password) {
debug(“Cargando configuración…”);
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
properties.put(Context.PROVIDER_URL, PROVIDER_URL);
try {
debug(“obtaining the initial context… the excecution collapse after this line”);
InitialContext context = new InitialContext(properties);
TopicConnectionFactory conFactory = (TopicConnectionFactory) context
.lookup(TOPIC_CONNECTION_FACTORY);
TopicConnection conexion = conFactory.createTopicConnection(
usuario, password);
TopicSession sesionP = conexion.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
TopicSession sesionS = conexion.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
Topic topicObj = (Topic) context.lookup(topico);
TopicSubscriber suscriptor = sesionS.createSubscriber(topicObj);
TopicPublisher publicador = sesionP.createPublisher(topicObj);
suscriptor.setMessageListener(this);
this.conexion = conexion;
this.sesionP = sesionP;
this.sesionS = sesionS;
this.publicador = publicador;
this.usuario = usuario;
conexion.start();
} catch (NamingException ne) {
throw new RuntimeException(“Error JNDI”, ne);
} catch (JMSException jmse) {
throw new RuntimeException(“Error JMS”, jmse);
}
}
————————————————————-
Error text:
————————————————————-
Exception in thread “main” java.lang.RuntimeException: Error JNDI
at jms_test.ClienteJMSChat.initialize(ClienteJMSChat.java:203)
at jms_test.ClienteJMSChat.main(ClienteJMSChat.java:86)
Caused by: javax.naming.NamingException: Operation getNameParser failed: java.io.StreamCorruptedException: invalid stream header: 01416374
at org.exolab.jms.jndi.mipc.NameServiceProxy.checkReply(NameServiceProxy.java:229)
at org.exolab.jms.jndi.mipc.NameServiceProxy.getNameParser(NameServiceProxy.java:85)
at org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory.getInitialContext(IpcJndiInitialContextFactory.java:144)
at org.exolab.jms.jndi.InitialContextFactory.getInitialContext(InitialContextFactory.java:109)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.(InitialContext.java:197)
at jms_test.ClienteJMSChat.initialize(ClienteJMSChat.java:153)
—————————————————————–
sneha gaur said
thanks for this wonderful link.
Andy said
Great info. However how do you configure the
the transport connectors to expose ActiveMQ over a given protocol to remote clients and other brokers that was configured in the activemq.xml file:
Subarshini Ramesh said
I followed the steps to deploy ActiveMQ war and then tried to start Tomcat server and getting the following exception. Do you have any idea to resolve the issue?
Apr 18, 2011 5:23:00 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /activemq-web-console-5.4.2 threw load() exception
javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exce
ption
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
java:1214)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:99
3)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContex
t.java:4149)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
458)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:77
1)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:850)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:724
)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:493
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:314)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)