Directly instantiate JMS Resources without using JNDI
Here's our simple example, rewritten to not use JNDI at all: We create the JMS ConnectionFactory object via the HornetQJMSClient Utility class, note we need to provide connection parameters and specify which transport we are using, for more information on connectors please see Chapter 16, Configuring the Transport. TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName()); ConnectionFactory cf = HornetQJMSClient.createConnectionFactory(transportConfiguration); We also create the JMS Queue object via the HornetQJMSClient Utility class: Queue orderQueue = HornetQJMSClient.createQueue("OrderQueue"); Next we create a JMS connection using the connection factory: Connection connection = cf.createConnection(); And we create a non transacted JMS Session, with AUTO_ACKNOWLEDGE acknowledge mode: Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); We create a MessageProducer that will send orders to the queue: MessageProducer producer = session.createProducer(orderQueue); And we create a MessageConsumer which will consume orders from the queue: MessageConsumer consumer = session.createConsumer(orderQueue); We make sure we start the connection, or delivery won't occur on it: connection.start(); We create a simple TextMessage and send it: TextMessage message = session.createTextMessage("This is an order"); producer.send(message); And we consume the message: TextMessage receivedMessage = (TextMessage)consumer.receive(); System.out.println("Got order: " + receivedMessage.getText());