1 Reply Latest reply on Feb 23, 2012 10:29 PM by jbertram

    Tip: simple JMS connection in HornetQ 2.2.5, no JNDI server

      For those of you wondering how to get HornetQ JMS working without a JNDI server on localhost

      in HornetQ version 2.2.5, here are some code excerpts.

      I didn't have a JNDI server because I was running a lightweight version of

      HornetQ as a servlet.

       

      I based this work on the blog

      http://hornetq.blogspot.com/2009/09/hornetq-simple-example-using-maven.html

       

      import java.util.Map;

      import java.util.HashMap;

      import org.hornetq.core.remoting.impl.netty.TransportConstants;

      import org.hornetq.api.core.TransportConfiguration;

      import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;

      import javax.jms.ConnectionFactory;

      import org.hornetq.jms.client.HornetQJMSConnectionFactory;

      import org.hornetq.api.core.TransportConfiguration;

      ....

       

                  // BEGIN: code derived from blog

                  // http://hornetq.blogspot.com/2009/09/hornetq-simple-example-using-maven.html

                  Map<String,Object> connectionParams = new HashMap<String,Object>();

                  connectionParams.put(TransportConstants.PORT_PROP_NAME, new Integer(5445));

                  TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);

       

                  ConnectionFactory cf = new HornetQJMSConnectionFactory(false, transportConfiguration);

       

                  // END: code derived from blog

       

                  // And the rest of the code is standard JMS

                  incomingConnection = cf.createConnection();

                  ....

       

      And here is a list of .jar files used for the build:

      jboss-jms-api.jar

      hornetq-jms-client.jar

      hornetq-core.jar

      hornetq-core-client.jar

      hornetq-jms.jar

      netty.jar