{
public static void main(final String[] args)
{
HornetQBootstrapServer hornetQ = null;
try
{
// Step 1. Start the server
hornetQ = new HornetQBootstrapServer("./server0/hornetq-beans.xml");
hornetQ.run();
// Step 2. As we are not using a JNDI environment we instantiate the objects directly
ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
ClientSessionFactory sf = serverLocator.createSessionFactory();
// Step 3. Create a core queue
ClientSession coreSession = sf.createSession(false, false, false);
final String queueName = "queue.exampleQueue";
coreSession.createQueue(queueName, queueName, true);
coreSession.close();
ClientSession session = null;
try
{
// Step 4. Create the session, and producer
session = sf.createSession();
ClientProducer producer = session.createProducer(queueName);
// Step 5. Create and send a message
ClientMessage message = session.createMessage(false);
final String propName = "myprop";
message.putStringProperty(propName, "Hello sent at " + new Date());
System.out.println("Sending the message.");
producer.send(message);
// Step 6. Create the message consumer and start the connection
ClientConsumer messageConsumer = session.createConsumer(queueName);
session.start();
// Step 7. Receive the message.
ClientMessage messageReceived = messageConsumer.receive(1000);
System.out.println("Received TextMessage:" + messageReceived.getStringProperty(propName));
}
finally
{
// Step 8. Be sure to close our resources!
if (sf != null)
{
sf.close();
}
// Step 9. Shutdown the container
if (hornetQ != null)
{
hornetQ.shutDown();
}
}
}
catch (Exception e)
{