Hi,

I am an ActiveMq newbie and I am trying to setup up the following
configuration in tomcat: One embedded broker and two wars. One of the wars
is the producer that posts to a queue and the other war consumes the
message.

My tomcat context.xml has the following entries:

<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"
                userName="activemq" password="activemq"
                clientID="TomcatClientID" />
  <Resource name="jms/segmentQueue" auth="Container"
                type="org.apache.activemq.command.ActiveMQQueue"
                description="JMS Queue"
                factory="org.apache.activemq.jndi.JNDIReferenceFactory"
                physicalName="SEGMENT.QUEUE" />

My activemq jars are in the common\lib directory for tomcat and the broker
is initialized by a servlet listener in the war that consumes the message.
Here is the code:

public void contextInitialized(ServletContextEvent contextEvent) {
        InitialContext init = null;
        ActiveMQConnectionFactory connectionFactory = null;
        ActiveMQQueue queue = null;
        Session session = null;

        String queueName =
PropertiesManager.getPropertyValue(EnumPropertiesNames.JMS_QUEUE_NAME);
        String connectionFactoryName =
PropertiesManager.getPropertyValue(EnumPropertiesNames.JMS_CONN_FACTORY_NAME);

        logger.debug("Initializing JMS queue with values: queue name = " +
            queueName + " and connection factory name = " +
            connectionFactoryName);

        try {
            //Obtain initial context
            init = new InitialContext();
            //Using the context locate the queue
            queue = (org.apache.activemq.command.ActiveMQQueue) init.lookup(
                    "java:comp/env/" + queueName);
            //Using the context locate the connection factory
            connectionFactory = (ActiveMQConnectionFactory) init.lookup(
                    "java:comp/env/" + connectionFactoryName);
        } catch (NamingException e) {
            logger.fatal("Unable to obtain queue/connectionFactory:" +
                e.getMessage(), e);
        }

        logger.debug("Successfully located connection factory and queue: " +
queue + ", " + connectionFactory);
        
        if ((connectionFactory != null) && (queue != null)) {
            try {
                //Obtain connection from connection factory
                connection = connectionFactory.createConnection();
                //Using the connection get a session
                session = connection.createSession(false,
                        Session.AUTO_ACKNOWLEDGE);

                //Create a JMS listener
                MessageConsumer consumer = session.createConsumer(queue);
                consumer.setMessageListener(new JMSMssgListener());
                connection.start();
            } catch (JMSException e) {
                logger.fatal("Unable to create session: " + e.getMessage(),
e);
            }
            
            logger.debug("Successfully created consumer and set message
listener");
        }
    }

I am able to successfully produce a message and the corresponding listener
in the second war retrieves it correctly. The problem is that within the
listener I want to do some processing and I am getting class not found
exceptions. Debugging the issue it seems that the thread for the listener
does not have the classpath for the war (evaluationg
System.getProperty(“java.class.path”) only returns
c:\tomcat\bin\bootstrap.jar).  

What am I missing? Why the listener seems to have the server classpath
instead of the applications? Is there any way to configure this?

Thanks in advance

Jairo


-- 
View this message in context: 
http://www.nabble.com/How-to-communicate-two-wars-in-Tomcat-tp22627876p22627876.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to