activemq-artemis/examples/jms/embedded
Martyn Taylor 56d6a47a83 ActiveMQ6-65 JBoss JMS1.1 -> Geronimo 2.0 spec jar
Replaces usage of the JBoss 1.1 API jar with the Geronimo JMS 2.0 jar.
The API is backwards compatibile.
2015-01-07 19:54:42 +00:00
..
src/main/java/org/apache/activemq/jms/example ACTIVEMQ6-51 Example server bootstrapping 2014-12-10 09:49:13 -06:00
pom.xml ActiveMQ6-65 JBoss JMS1.1 -> Geronimo 2.0 spec jar 2015-01-07 19:54:42 +00:00
readme.html ACTIVEMQ6-43(reopened) : Replace License Headers on codebase 2015-01-05 13:14:25 -05:00

readme.html

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<html>
   <head>
      <title>ActiveMQ Embedded JMS Server 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>Embedded JMS Server Example</h1>
      
      <p>This examples shows how to setup and run an embedded JMS server using ActiveMQ.</p>
      <p>ActiveMQ was designed using POJOs (Plain Old Java Objects) which means embedding ActiveMQ in your own application
          is as simple as instantiating a few objects.</p>
      <p>This example does not use any configuration files. The server is configured using POJOs and can be easily ported to any dependency injection framework.<br /> 
         We will setup and run a full-fledged JMS server which binds its JMS resources to JNDI and can be accessed by remote clients.</p>
     
      <h2>Example step-by-step</h2>     
      <p><i>To run the example, simply type <code>mvn verify</code> from this directory</i></p>

      <ol>
         <li>Create ActiveMQ core configuration, and set the properties accordingly</li>
         <pre class="prettyprint">
            <code>Configuration configuration = new ConfigurationImpl();
            configuration.setPersistenceEnabled(false);
            configuration.setSecurityEnabled(false);
            configuration.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));</code>
            Configuration configuration = new ConfigurationImpl();</pre>

         <li>Create the ActiveMQ core server</li>
         <pre class="prettyprint">
            <code>ActiveMQServer activemqServer = ActiveMQ.newActiveMQServer(configuration);</code>
         </pre>

         <li>Create the JMS configuration</li>
         <pre class="prettyprint">
            <code>JMSConfiguration jmsConfig = new JMSConfigurationImpl();</code>
         </pre>

         <li>Configure the JMS ConnectionFactory</li>
         <pre class="prettyprint">
            <code>TransportConfiguration connectorConfig = new TransportConfiguration(NettyConnectorFactory.class.getName());
            ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl("cf", connectorConfig, "/cf");
            jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);</code>
         </pre>
         
         <li>Configure the JMS Queue</li>
         <pre class="prettyprint">
            <code>QueueConfiguration queueConfig = new QueueConfigurationImpl("queue1", null, false, "/queue/queue1");
            jmsConfig.getQueueConfigurations().add(queueConfig);</code>
         </pre>
     
         <li>Start the JMS Server using the ActiveMQ core server and the JMS configuration</li>
         <pre class="prettyprint">
            <code>JMSServerManager jmsServer = new JMSServerManagerImpl(activemqServer, jmsConfig);
            jmsServer.start();</code>
         </pre>

         <p>At this point the JMS server is started and any JMS clients can look up JMS resources from JNDI to send/receive 
            messages from the server. To keep the example simple, we will send and receive a JMS message from the same JVM 
            used to run the JMS server.</p>
              
         <li>Lookup JMS resources defined in the configuration </li>
         <pre class="prettyprint">
            <code>ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf");
            Queue queue = (Queue)context.lookup("/queue/queue1");</code>
         </pre>
         
         <li>Send and receive a message using JMS API</li>
         <p>See the <a href="../../queue/readme.html">Queue Example</a> for detailed steps to send and receive a JMS message</p>
           
         <p>Finally, we stop the JMS server and its associated resources.</p>
        
         <li>Stop the JMS server</li>
         <pre class="prettyprint">
            <code>jmsServer.stop();</code>
         </pre>
        
         <li>Stop the JNDI server</li>
         <pre class="prettyprint">
            <code>naming.stop();</code>
         </pre>
      </ol>
   </body>
</html>