2 Replies Latest reply on May 17, 2013 6:24 AM by petal1

    Simple JMS listener terminates on connection.start with HornetQ (works with JBossMQ)

    petal1

      Hello,

       

      I just wrote a imple standalone Java program that acts as a MessageListener. When I run it and with JBoss 4.0.4 hosting the queue (so JBossMQ is provider) it works fine. When I run it with JBoss 6.1.0 hosting the queue (so HornetQ 2,2,5) then the program terminates after calling connection.start(). No exceptions are thrown (exception handlers not shown below to cut code down); the program just exits after the call to m_connection.start()

       

          import javax.jms.Connection;

          import javax.jms.ConnectionFactory;

          import javax.jms.Destination;

          import javax.jms.JMSException;

          import javax.jms.Message;

          import javax.jms.MessageConsumer;

          import javax.jms.MessageListener;

          import javax.jms.Session;

          import javax.jms.TextMessage;

          import javax.naming.InitialContext;

          import javax.naming.NamingException;

       

          public class JMSMessageListener implements MessageListener

          {

              private                    Connection          m_connection = null;

              protected          Session          m_session = null;

              protected          MessageConsumer          m_consumer;

              protected String m_resourceLocation;

              protected String m_resourceName;

              protected String m_baseResourceName = null;

              protected String m_resourceType = null;

       

              protected Hashtable<String,String>          m_jndiProperties = new Hashtable<String,String>();

       

              public JMSMessageListener(String resourceLocation, String resourceName)

              {

                  m_resourceLocation = "jnp://" +resourceLocation+ ":1099";

                  m_resourceName = resourceName;

       

                  m_jndiProperties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                  m_jndiProperties.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                  m_jndiProperties.put(javax.naming.Context.PROVIDER_URL, m_resourceLocation);

       

                  InitialContext context;

                  ConnectionFactory connectionFactory;

                  Destination destination = null;

             

                  context = new InitialContext(m_jndiProperties);

                  connectionFactory = (ConnectionFactory)context.lookup("ConnectionFactory");

                  destination = (Destination)context.lookup(m_resourceName);

                 

                  m_connection = connectionFactory.createConnection();

                  m_session = m_connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                  m_consumer = m_session.createConsumer(destination);

                  m_consumer.setMessageListener(this);

              }


             public void startListening()

              {

                  m_connection.start();

              }


             public void onMessage(Message message)

              {

                 ...

              }

       

             public static void main(String args[])

              {

                  new JMSMessageListener(args[0],args[1]).startListening();

              }

          }

       

      I execute the program like this:

      java -classpath "./jmsmessager.jar:<path to>/jboss-6.1.0.Final/client/jboss-jms-api_1.1_spec.jar:<path to>/jboss-6.1.0.Final/client/jnp-client.jar:<path to>/jboss-6.1.0.Final/client/jboss-logging.jar:<path to>/jboss-6.1.0.Final/client/hornetq-jms-client.jar:<path to>/jboss-6.1.0.Final/client/hornetq-core-client.jar:<path to>/jboss-6.1.0.Final/client/netty.jar" test.jms.receiver.JMSMessageListener localhost queue/MyTestQueue

       

      Thanks for any help,

      Paul