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, simply type ./build.sh deploy
(or build.bat deploy
on windows)from the example directory
Once the server has started simply type ./build.sh run
(or build.bat run
on windows) to run the example.
To remove the new profile type simply type ./build.sh undeploy
(or build.bat undeploy
on windows).
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();
}
}