package org.hornet.hornetq; import javax.jms.JMSException; import javax.naming.NamingException; public class HornetQDemo { javax.naming.Context ic = null; javax.jms.ConnectionFactory cf = null; javax.jms.Connection connection = null; javax.jms.Queue queue = null; javax.jms.Session session = null; String destinationName = "queue/DLQ"; public void getInitialContext() throws NamingException { java.util.Properties p = new java.util.Properties(); p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); p.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:1099"); ic = new javax.naming.InitialContext(p); } public void connectAndCreateSession() throws NamingException, JMSException { // lookup the connection factory from the hornet-jms.xml file cf = (javax.jms.ConnectionFactory) ic.lookup("/ConnectionFactories"); // this is the default queue created by the distribution of hornetQ queue = (javax.jms.Queue) ic.lookup(destinationName); // create a connection connection = cf.createConnection(); // createSession(transaction been supported/added ot not?,Mode used...) session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); connection.start(); } public static void main(String args[]) { try { HornetQDemo hornetQDemo = new HornetQDemo(); hornetQDemo.getInitialContext(); hornetQDemo.connectAndCreateSession(); } catch (NamingException namingException) { namingException.printStackTrace(); } catch (JMSException jmsException) { jmsException.printStackTrace(); } catch (Exception exception) { exception.printStackTrace(); } } }