activemq-artemis/examples/core/microcontainer
Andy Taylor 8ecd255f98 ACTIVEMQ6-1 - Initial HornetQ Donation Commit
https://issues.apache.org/jira/browse/ACTIVEMQ6-1

This is the initial donation of the HornetQ codebase as per document http://incubator.apache.org/ip-clearance/hornetq.html
2014-11-10 10:31:25 -06:00
..
src/main ACTIVEMQ6-1 - Initial HornetQ Donation Commit 2014-11-10 10:31:25 -06:00
pom.xml ACTIVEMQ6-1 - Initial HornetQ Donation Commit 2014-11-10 10:31:25 -06:00
readme.html ACTIVEMQ6-1 - Initial HornetQ Donation Commit 2014-11-10 10:31:25 -06:00

readme.html

<html>
  <head>
    <title>HornetQ Embedded Example</title>
    <link rel="stylesheet" type="text/css" href="../../common/common.css" />
    <link rel="stylesheet" type="text/css" href="../../common/prettify.css" />
    <script type="text/javascript" src="../../common/prettify.js"></script>
  </head>
  <body onload="prettyPrint()">
     <h1>Micro Container Example</h1>

     <p>This examples shows how to setup and run HornetQ through the Micro Container.</p>
     <p>Refer to the user's manual for the list of required Jars, since JBoss Micro Container requires a few jars.</p>
     <h2>Example step-by-step</h2>     
     <p><i>To run the example, simply type <code>mvn verify</code> from this directory</i></p>
     <p>In this we don't use any configuration files. (Everything is embedded). We simply instantiate ConfigurationImpl, HornetQServer, start it and operate on JMS regularly</p>

     <ol>
     
        <li>Start the server</li>
        <pre class="prettyprint">
           hornetq = new HornetQBootstrapServer("./server0/hornetq-beans.xml");
           hornetq.run();
        </pre>
     
        <li>As we are not using a JNDI environment we instantiate the objects directly</li>
        <pre class="prettyprint">
           ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
           ClientSessionFactory sf = serverLocator.createSessionFactory();
        </pre>

        <li>Create a Core Queue</li>
        <pre class="prettyprint">
           ClientSession coreSession = sf.createSession(false, false, false);
           final String queueName = "queue.exampleQueue";
           coreSession.createQueue(queueName, queueName, true);
           coreSession.close();
        </pre>

        <li>Create the session and producer</li>
        <pre class="prettyprint">
           session = sf.createSession();
                                   
           ClientProducer producer = session.createProducer(queueName);
        </pre>

        <li>Create and send a Message</li>
        <pre class="prettyprint">
           ClientMessage message = session.createMessage(false);
           message.putStringProperty(propName, "Hello sent at " + new Date());
           System.out.println("Sending the message.");
           producer.send(message);
        </pre>

        <li>Create the message consumer and start the connection</li>
        <pre class="prettyprint">
           ClientConsumer messageConsumer = session.createConsumer(queueName);
           session.start();
        </pre>

        <li>Receive the message</li>
        <pre class="prettyprint">
           ClientMessage messageReceived = messageConsumer.receive(1000);
           System.out.println("Received TextMessage:" + messageReceived.getProperty(propName));
         </pre>

        <li>Be sure to close our resources!</li>

        <pre class="prettyprint">
           if (sf != null)
           {
              sf.close();
           }
        </pre>

        <li>Stop the server</li>

        <pre class="prettyprint">
           hornetq.shutdown();
        </pre>
     </ol>
  </body>
</html>