Announcement Announcement Module
No announcement yet.
JMS / ActiveMQ / Tomcat / Spring Integration Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMS / ActiveMQ / Tomcat / Spring Integration

    I'm trying to prototype the integration part of an upcoming project. (I've read the message patterns, and know roughly what is going on at a high level with asynch messaging, but haven't done anything hands onwith it before). What I want to end up with is:

    1) Client Webapp that sends messages to a queue and reads responses from a response queue.
    2) Either another Webapp that host the queue, or set up the server to host the queue
    3) Server Webapp that processes the client messages and provides a response.

    What I have at the moment is:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns=""
    	<annotation-driven />
    	<message-bus error-channel="errorChannel" />
    	<channel id="errorChannel" publish-subscribe="true" capacity="500" />
    	<channel id="testChannel"/>
    	<endpoint input-channel="testChannel" handler-ref="testSender">
    		<!-- NOTE: A.B. 22/2/8 concurrency has some reasonable defaults but we probably want to explicitly define them because we will have some knowledge about the load and performance profiles we expect -->
    		<concurrency core="2" max="4" queue-capacity="100" keep-alive="20" />
    	<jms-source connection-factory="connectionFactory" destination="testInputQueue" channel="testChannel"/>
    	<beans:bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    		<beans:property name="brokerURL"><beans:value>tcp://localhost:61616</beans:value></beans:property>
    	<!-- <jms-target connection-factory="connectionFactory" destination="outputQueue" channel="outputChannel1"/> -->
    	<beans:bean id="testSender"
    public class TestHandler implements MessageHandler {
        public Message<?> handle(Message<?> message) {
            System.out.println("I handled a message");
            return null;
        public static void main(String[] args) {
            AbstractApplicationContext context = new ClassPathXmlApplicationContext(
                "/main/webapp/WEB-INF/applicationContext-integration.xml", TestHandler.class);
            ChannelRegistry channelRegistry = (ChannelRegistry) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
            MessageChannel inputChannel = channelRegistry.lookupChannel("testChannel");
            MessageChannel outputChannel = channelRegistry.lookupChannel("testChannel");
            inputChannel.send(new StringMessage("World"));
      <Resource name="jms/ConnectionFactory" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory"
            factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="vm://localhost" brokerName="LocalActiveMQBroker"/>
            <!-- Publish - subscribe example -->
      		<!--Resource name="jms/someTopic" auth="Container" type="org.apache.activemq.command.ActiveMQTopic" description="my Topic"
            factory="org.apache.activemq.jndi.JNDIReferenceFactory" physicalName="FOO.BAR"/-->
      <Resource name="testInputQueue" auth="Container" type="org.apache.activemq.command.ActiveMQQueue" description="my Queue"
            factory="org.apache.activemq.jndi.JNDIReferenceFactory" physicalName="FOO.BAR"/>
    When I start the TestHandler it attempts to load applicationContext-integration.xml but fails with "No bean named 'testInputQueue' is defined"
    What am I supposed to do to get the connectionFactory pointing to the deployed jms/connectionFactory rather than a locally created instance?

    Tomcat 6.0
    Spring Integration 1.0.0.m1
    ActiveMQ 5.0.0

  • #2
    You can use something like the following (in your spring configuration):
    <jee:jndi-lookup id="connectionFactory" jndi-name="jms/ConnectionFactory" resource-ref="true"/>
    <jee:jndi-lookup id="testInputQueue" jndi-name="testInputQueue" resource-ref="true"/>


    • #3
      That results in a 4999 line stack trace with most lines complaining about:
      Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial


      • #4
        You need to provide the JNDI environment properties. Typically that is done with a "" file on the classpath. Otherwise, you can set the properties with a <jee:jndi-environment/> sub-element of the <jee:jndi-lookup/>.

        Have a look at the jndi-lookup examples in the reference (especially the inclusion of the jndi environment properties):

        You can consult your JNDI provider's documentation for the required property values (e.g. java.naming.factory.initial=???)



        • #5
          Thanks for the help. I've managed to get something going where the messages are handled, but have used a local ActiveMQ deployment rather than using Tomcat. Will try using Tomcat again after I get some more sleep.