This example shows you how to configure ActiveMQ server to communicate with an ActiveMQ JMS client using ActiveMQ's native openwire protocol.
To run the example, simply type mvn verify -Pexample
from this directory
ConnectionFactory factory = new ActiveMQConnectionFactory(urlString);
Queue queue = new ActiveMQQueue("exampleQueue");
connection = cf.createConnection();
connection.start()
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(topic);
TextMessage message = session.createTextMessage("This is a text message");
messageProducer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
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 (connection != null)
{
connection.close();
}
}