0
votes

I am trying to set up an ActiveMQ broker within the context of a web app hosted in Tomcat. Additionally, the connector that I want to use is TCP as eventually this broker should be accessible from remote applications.

So far, what I have done is to create a simple web app with a local JNDI context.xml configuration like the following:

<Resource auth="Container"
    name="jms/ConnectionFactory"
    type="org.apache.activemq.ActiveMQConnectionFactory"
    description="JMSConnection"
    factory="org.apache.activemq.jndi.JNDIReferenceFactory"
    brokerURL="tcp://localhost:61616"
    brokerName="MQBroker"/>

<Resource auth="Container"
    name="jms/MQueue"
    type="org.apache.activemq.command.ActiveMQQueue"
    description="JMS queue"
    factory="org.apache.activemq.jndi.JNDIReferenceFactory"
    physicalName="SOME.QUEUE"/>

I have updated the web.xml file accordingly and called the connection factory from a ServletContextListener implementing class as follows:

InitialContext context = new InitialContext();
Context cntx = (Context) context.lookup("java:comp/env");
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) cntx.lookup("jms/ConnectionFactory");
factory.createQueueConnection();

When deploying the app, I get an exception:

Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused

I think this is because there is no configuration for the broker itself, as in online examples I see that files with Spring configuration are attached to the brokerUrl attribute of the resource. The issue is that the project environment is strictly defined, so I cannot use spring to provide the configuration. I have also seen some solutions with Camel, but that is also out of the question.

So to sum up, the questions are:

  1. Is it possible to set up an ActiveMQ broker local to a web app, that can be accessed over the network by remote applications?
  2. Is explicit configuration needed for the broker?
  3. If yes, can this be done without using Spring for the broker configuration, but rather with a properties file or something similar that does not add dependencies to the project?
1

1 Answers

1
votes

You can have ActiveMQ broker embedded in your application or as a stand alone Java program. It does not need Spring for broker configuration.

http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html