This example shows you how to configure and use servlet transport with HornetQ.
Please refer to HornetQ Quickstart guide to install it in JBoss AS 5
To deploy and start the server, type ant deployfrom the example directory
Once the server has started type ant run to run the example.
To remove the new profile type ant undeploy.
jndi.properties file in the directory config
initialContext = new InitialContext();
Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/TestServletConnectionFactory");
connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(queue);
TextMessage message = session.createTextMessage("This is a text message");
messageProducer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
connection.start();
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
finally
{
if (initialContext != null)
{
initialContext.close();
}
if (connection != null)
{
connection.close();
}
}