This examples shows how to setup and run HornetQ through the Micro Container.
Refer to the user's manual for the list of required Jars, since JBoss Micro Container requires a few jars.
To run the example, simply type ant from this directory
In this we don't use any configuration files. (Everything is embedded). We simply instantiate ConfigurationImpl, HornetQServer, start it and operate on JMS regularly
hornetq = new HornetQBootstrapServer("./server0/hornetq-beans.xml");
hornetq.run();
ClientSessionFactory sf = new ClientSessionFactoryImpl (new TransportConfiguration(NettyConnectorFactory.class.getName()));
ClientSession coreSession = sf.createSession(false, false, false);
final String queueName = "queue.exampleQueue";
coreSession.createQueue(queueName, queueName, true);
coreSession.close();
session = sf.createSession();
ClientProducer producer = session.createProducer(queueName);
ClientMessage message = session.createClientMessage(false);
message.putStringProperty(propName, "Hello sent at " + new Date());
System.out.println("Sending the message.");
producer.send(message);
ClientConsumer messageConsumer = session.createConsumer(queueName);
session.start();
ClientMessage messageReceived = messageConsumer.receive(1000);
System.out.println("Received TextMessage:" + messageReceived.getProperty(propName));
finally
{
if (connection != null)
{
connection.close();
}
}
hornetq.shutdown();