You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by bu...@apache.org on 2016/11/10 22:22:29 UTC

svn commit: r1000918 - in /websites/production/activemq/content: cache/main.pageCache how-to-unit-test-jms-code.html jndi-support.html

Author: buildbot
Date: Thu Nov 10 22:22:29 2016
New Revision: 1000918

Log:
Production update by buildbot for activemq

Modified:
    websites/production/activemq/content/cache/main.pageCache
    websites/production/activemq/content/how-to-unit-test-jms-code.html
    websites/production/activemq/content/jndi-support.html

Modified: websites/production/activemq/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/activemq/content/how-to-unit-test-jms-code.html
==============================================================================
--- websites/production/activemq/content/how-to-unit-test-jms-code.html (original)
+++ websites/production/activemq/content/how-to-unit-test-jms-code.html Thu Nov 10 22:22:29 2016
@@ -44,7 +44,7 @@
       </script> 
     
     <title>
-    Apache ActiveMQ &#8482; -- How to unit test JMS code
+    Apache ActiveMQ &#8482; -- How To Unit Test JMS Code
     </title>
 </head>
 <body>
@@ -71,7 +71,7 @@
 <p></p>
         <div class="top_red_bar">
           <div id="site-breadcrumbs">
-<a href="community.html">Community</a>&nbsp;&gt;&nbsp;<a href="faq.html">FAQ</a>&nbsp;&gt;&nbsp;<a href="jms.html">JMS</a>&nbsp;&gt;&nbsp;<a href="how-to-unit-test-jms-code.html">How to unit test JMS code</a>
+<a href="community.html">Community</a>&nbsp;&gt;&nbsp;<a href="faq.html">FAQ</a>&nbsp;&gt;&nbsp;<a href="jms.html">JMS</a>&nbsp;&gt;&nbsp;<a href="how-to-unit-test-jms-code.html">How To Unit Test JMS Code</a>
           </div>
           <div id="site-quicklinks">
 <p><a shape="rect" href="download.html">Download</a> | <a shape="rect" class="external-link" href="http://activemq.apache.org/maven/apidocs/index.html">JavaDocs</a> <a shape="rect" href="javadocs.html">More...</a> | <a shape="rect" href="source.html">Source</a> | <a shape="rect" href="discussion-forums.html">Forums</a> | <a shape="rect" href="support.html">Support</a></p>
@@ -82,7 +82,7 @@
   <tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><p>When unit testing code with JMS you'll typically want to avoid the overhead of running separate proceses; plus you'll want to increase startup time as fast as possible as you tend to run unit tests often and want immediate feedback. Also persistence can often cause problems - as previous test case results can adversely affect future test case runs - so you often need to purge queues on startup.</p><p>So when unit testing JMS code we recommend the following</p><ul><li>Use <a shape="rect" href="how-do-i-embed-a-broker-inside-a-connection.html">an embedded broker</a> to avoid a separate broker process being required</li><li>Disable <a shape="rect" href="broker-configuration-uri.html">broker persistence</a> so that no queue purging is required before/after tests</li><li>It's often simpler and faster to just use Java code to create the broker via an XML configuration file using Spring etc.</li></ul><p>You can do all of this using the following Jav
 a code to create your JMS ConnectionFactory which will also automatically create an embedded broker</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<div class="wiki-content maincontent"><p>When unit testing code with JMS you'll typically want to avoid the overhead of running separate proceses; plus you'll want to increase startup time as fast as possible as you tend to run unit tests often and want immediate feedback. Also persistence can often cause problems - as previous test case results can adversely affect future test case runs - so you often need to purge queues on startup.</p><p>So when unit testing JMS code we recommend the following</p><ul><li>Use <a shape="rect" href="how-do-i-embed-a-broker-inside-a-connection.html">an embedded broker</a> to avoid a separate broker process being required.</li><li>Disable <a shape="rect" href="broker-configuration-uri.html">broker persistence</a> so that no queue purging is required before/after tests.</li><li>It's often simpler and faster to just use Java code to create the broker via an XML configuration file using Spring etc.</li></ul><p>You can do all of this using the following J
 ava code to create your JMS&#160;<strong><code>ConnectionFactory</code></strong> which will also automatically create an embedded broker</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
 </pre>
 </div></div><p>For more configuration options see the <a shape="rect" href="vm-transport-reference.html">VM Transport Reference</a> and the <a shape="rect" href="broker-configuration-uri.html">Broker Configuration URI</a></p><p>Or if you really would rather be more explicit you can create the broker first using the following Java code</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
@@ -90,12 +90,12 @@
 broker.setPersistent(false);
 broker.start();
 </pre>
-</div></div><p>or you could use the <a shape="rect" href="spring-support.html">Spring Support</a></p><h3 id="HowtounittestJMScode-UsingJNDI">Using JNDI</h3><p>If your application code is using JNDI to lookup the JMS ConnectionFactory and Destinations to use, then you could use the&#160;<a shape="rect" href="jndi-support.html">JNDI Support</a>&#160;in ActiveMQ.</p><p>Add the following jndi.properties to your classpath (e.g. in src/test/resources if you are using maven).</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>or you could use <a shape="rect" href="spring-support.html">Spring Support.</a></p><h3 id="HowToUnitTestJMSCode-UsingJNDI">Using JNDI</h3><p>If your application code is using JNDI to lookup the JMS&#160;<strong><code>ConnectionFactory</code></strong> and <strong><code>Destination</code></strong>'s to use, then you could use the&#160;<a shape="rect" href="jndi-support.html">JNDI Support</a>&#160;in ActiveMQ.</p><p>Add the following&#160;<strong><code>jndi.properties</code></strong> to your classpath, e.g., in&#160;<strong><code>src/test/resources</code></strong>, if you are using maven:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
 java.naming.provider.url = vm://localhost?broker.persistent=false</pre>
 </div></div><p>You should then consider using&#160;<a shape="rect" href="jndi-support.html">Dynamic destinations in JNDI</a>&#160;so that your code looks up destinations via</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">context.lookup("dynamicQueues/FOO.BAR");</pre>
-</div></div><h3 id="HowtounittestJMScode-UsingtheEmbeddedActiveMQBrokerJUnitRule(ActiveMQ5.13)">Using the EmbeddedActiveMQBroker JUnit Rule (ActiveMQ 5.13)</h3><p>If your test code is using JUnit, then you could use the EmbeddedActiveMQBroker JUnit Rule provided&#160;in the activemq-junit library.</p><p>Add the activemq-junit library along with the activemq-broker libraries for the version of ActiveMQ you want to test with. &#160;The rule will use whatever version of ActiveMQ it finds in the classpath, so the ActiveMQ libraries need to be specified if they are not already there.</p><p>If you are using Maven, add the following to your pom.xml</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Maven configuration for JUnit Rule</b></div><div class="codeContent panelContent pdl">
+</div></div><h3 id="HowToUnitTestJMSCode-UsingTheEmbeddedActiveMQBrokerJUnitRule(ActiveMQ5.13)">Using The&#160;<code>EmbeddedActiveMQBroker</code> JUnit Rule (ActiveMQ 5.13)</h3><p>If your test code is using JUnit, then you could use the&#160;<strong><code>EmbeddedActiveMQBroker</code></strong> JUnit Rule provided&#160;in the&#160;<strong><code>activemq-junit</code></strong> library. Add the&#160;<strong><code>activemq-junit</code></strong> library along with the&#160;<strong><code>activemq-broker</code></strong> libraries for the version of ActiveMQ you want to test with. &#160;The rule will use whatever version of ActiveMQ it finds in the classpath, so the ActiveMQ libraries need to be specified if they are not already there.</p><p>If you are using Maven, add the following to your <strong><code>pom.xml</code></strong>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;dependency&gt;
     &lt;groupId&gt;org.apache.activemq.tooling&lt;/groupId&gt;
     &lt;artifactId&gt;activemq-junit&lt;/artifactId&gt;
@@ -109,22 +109,22 @@ java.naming.provider.url = vm://localhos
     &lt;version&gt;${activemq-version}&lt;/version&gt;
     &lt;scope&gt;test&lt;/scope&gt;
 &lt;/dependency&gt;</pre>
-</div></div><p>&#160;Then add the EmbeddedActiveMQBroker JUnit Rule to your test, and JUnit will start the embedded broker at the beginning of each test and stop the broker at the end of the test.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Use ActiveMQ JUnit Rule</b></div><div class="codeContent panelContent pdl">
+</div></div><p>&#160;Then add the&#160;<strong><code>EmbeddedActiveMQBroker</code></strong> JUnit Rule to your test, and JUnit will start the embedded broker at the beginning of each test and stop the broker at the end of the test.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Use The ActiveMQ JUnit Rule</b></div><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">@Rule
 public EmbeddedActiveMQBroker broker = new EmbeddedActiveMQBroker();</pre>
-</div></div><p>By default, the EmbeddedActiveMQBroker will configure the broker as non-persistent, and the only transport available will be the VM transport. &#160;To customize this configuration, either extend the EmbeddedActiveMQBroker class and override the configure() method, or use an XML configuration for the broker. &#160;Note that to use the XML configuration, you may to to add additional libraries on the classpath to support the XBean configuration of ActiveMQ.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Customize EmbeddedActiveMQBroker using Java configuration</b></div><div class="codeContent panelContent pdl">
+</div></div><p>By default, the&#160;<strong><code>EmbeddedActiveMQBroker</code></strong> will configure the broker as non-persistent, and the only transport available will be the VM transport. To customize this configuration, either extend the&#160;<strong><code>EmbeddedActiveMQBroker</code></strong> class and override the&#160;<strong><code>configure()</code></strong> method, or use an XML configuration for the broker. &#160;</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><strong>Note</strong>: to configure an <strong><code>EmbeddedActiveMQBroker</code></strong> using XML configuration, you may need to add additional libraries to the classpath to support XBean configuration of ActiveMQ.</div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="bord
 er-bottom-width: 1px;"><b>Customizing An EmbeddedActiveMQBroker Using Java</b></div><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">@Rule
 EmbeddedActiveMQBroker customizedBroker = new EmbeddedActiveMQBroker() {
     @Override
     protected void configure() {
-        // Perform additional configuration here
+        // Perform additional configuration here...
     }
 }</pre>
-</div></div><p><span>Note that to use the XML configuration, you may to to add additional libraries on the classpath to support the XBean configuration of ActiveMQ.</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Customize EmbeddedActiveMQBroker using XML configuration</b></div><div class="codeContent panelContent pdl">
+</div></div><p><span><br clear="none"></span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Customizing An EmbeddedActiveMQBroker Using XML Configuration</b></div><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">@Rule
 EmbeddedActiveMQBroker customizedBroker = new EmbeddedActiveMQBroker("bean:customize-activemq.xml");
 </pre>
-</div></div><p>Note that to use the XML configuration, you may need to add additional libraries on the classpath to support the XBean configuration of ActiveMQ. &#160;The versions of the spring-context library should correspond with the version used by your selected version of ActiveMQ.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Maven configuration for XBean configuration</b></div><div class="codeContent panelContent pdl">
+</div></div><p>Note that to use the XML configuration, you may need to add additional libraries on the classpath to support the XBean configuration of ActiveMQ. &#160;The versions of the&#160;<strong><code>spring-context</code></strong> library should correspond with the version used by your selected version of ActiveMQ.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Maven Configuration For XBean Configuration</b></div><div class="codeContent panelContent pdl">
 <pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;dependency&gt;
     &lt;groupId&gt;org.springframework&lt;/groupId&gt;
     &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
@@ -138,7 +138,7 @@ EmbeddedActiveMQBroker customizedBroker
 &lt;/dependency&gt;</pre>
 </div></div><p>Then you can use the VM URI to connect with the broker</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://embedded-broker?create=false");</pre>
-</div></div><p>You can also get a connection factory from the EmbeddedActiveMQBroker</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>You can also get a connection factory from the <strong><code>EmbeddedActiveMQBroker</code></strong>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">ConnectionFactory connectionFactory = embeddedBroker.createConnectionFactory();</pre>
 </div></div></div>
         </td>

Modified: websites/production/activemq/content/jndi-support.html
==============================================================================
--- websites/production/activemq/content/jndi-support.html (original)
+++ websites/production/activemq/content/jndi-support.html Thu Nov 10 22:22:29 2016
@@ -81,70 +81,59 @@
   <tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><p>ActiveMQ will work with any JNDI provider capable of storing Java objects.</p><p>However it is common to require a JNDI initial context to be able to run many JMS example programs, like <a shape="rect" class="external-link" href="http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/jms_tutorialTOC.html" rel="nofollow">Sun's JMS tutorial</a></p><p>So we provide a simple JNDI InitialContextFactory which can be used to lookup JMS connection factory objects as well as Destination objects.</p><p>For example if you place this <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/activemq/trunk/activemq-unit-tests/src/test/resources/jndi.properties">jndi.properties</a> file on your classpath, you can look inside the InitialContext and lookup ConnectionFactory objects and Destinations etc.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<div class="wiki-content maincontent"><p>ActiveMQ will work with any JNDI provider capable of storing Java objects. However it is common to require a JNDI initial context to be able to run many JMS example programs, like <a shape="rect" class="external-link" href="http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/jms_tutorialTOC.html" rel="nofollow">Sun's JMS tutorial.</a></p><p>So we provide a simple JNDI&#160;<strong><code>InitialContextFactory</code></strong> which can be used to lookup JMS connection factory objects as well as Destination objects. For example if you place this <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/activemq/trunk/activemq-unit-tests/src/test/resources/jndi.properties">jndi.properties</a> file on your classpath, you can look inside the&#160;<strong><code>InitialContext</code></strong> and lookup&#160;<strong><code>ConnectionFactory</code></strong> objects and&#160;<strong><code>Destinations</code></strong> etc.</p><div c
 lass="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
 
-# use the following property to configure the default connector
+# Use the following property to configure the default connector
 java.naming.provider.url = vm://localhost
 
-# use the following property to specify the JNDI name the connection factory
+# Use the following property to specify the JNDI name the connection factory
 # should appear as. 
 #connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
 
-# register some queues in JNDI using the form
-# queue.[jndiName] = [physicalName]
+# Register some queues in JNDI using the form:
+#   queue.[jndiName] = [physicalName]
 queue.MyQueue = example.MyQueue
 
-# register some topics in JNDI using the form
-# topic.[jndiName] = [physicalName]
+# Register some topics in JNDI using the form:
+#   topic.[jndiName] = [physicalName]
 topic.MyTopic = example.MyTopic</pre>
-</div></div><p>You can edit the jndi.properties file to configure the ActiveMQConnectionFactory's properties such as brokerURL and whether or not there should be an embedded broker etc. See <a shape="rect" href="how-do-i-embed-a-broker-inside-a-connection.html">how to embed a broker in a connection</a> for more details.</p><h3 id="JNDISupport-ActiveMQJNDITutorial">ActiveMQ JNDI Tutorial</h3><p>This is a quick one page tutorial on how to setup and use JNDI to create a connection to ActiveMQ. The first thing is ActiveMQ does not provide a full JNDI server. This means JMS clients need to use properties files to create a jndi IntialContextFactory. If you need an example properties file, you can look the source distribution <a shape="rect" class="external-link" href="https://github.com/apache/activemq/blob/master/activemq-unit-tests/src/test/resources/jndi.properties" rel="nofollow">https://github.com/apache/activemq/blob/master/activemq-unit-tests/src/test/resources/jndi.properties</a>.
  Before we proceed, here are the properties.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>java.naming.factory.initial</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>org.apache.activemq.jndi.ActiveMQInitialContextFactory</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>java.naming.provider.url</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>tcp://hostname:61616</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>topic.MyTopic</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>example.MyTopic</p></td></tr></tbody></table></div><p>Make sure to add activemq-&lt;version&gt;.jar and spring-1.x.jar to your classpath. If the libraries are not in the classpath, you will get a "ClassNotFoundException" at runtim
 e. If you get "ClassNotFoundException", try printing out the classpath and check it is present. You can also run activeMQ with "-verbose" option to verify the jar was loaded correctly.</p><p><strong>Sample code</strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">// create a new intial context, which loads from jndi.properties file
+</div></div><p>You can edit the&#160;<strong><code>jndi.properties</code></strong> file to configure the <strong><code>ActiveMQConnectionFactory</code></strong>'s properties such as&#160;<strong><code>brokerURL</code></strong> and whether or not there should be an embedded broker etc. See <a shape="rect" href="how-do-i-embed-a-broker-inside-a-connection.html">how to embed a broker in a connection</a> for more details.</p><h3 id="JNDISupport-ActiveMQJNDITutorial">ActiveMQ JNDI Tutorial</h3><p>This is a quick one page tutorial on how to setup and use JNDI to create a connection to ActiveMQ. The first thing is ActiveMQ does not provide a full JNDI server. This means JMS clients need to use properties files to create a JNDI <strong><code>IntialContextFactory</code></strong>. If you need an example properties file, you can look the source distribution <a shape="rect" class="external-link" href="https://github.com/apache/activemq/blob/master/activemq-unit-tests/src/test/resources/jndi.pro
 perties" rel="nofollow">https://github.com/apache/activemq/blob/master/activemq-unit-tests/src/test/resources/jndi.properties</a>. Before we proceed, here are the properties.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>java.naming.factory.initial</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.activemq.jndi.ActiveMQInitialContextFactory</code></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>java.naming.provider.url</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>tcp://hostname:61616</code></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>topic.MyTopic</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>example.MyTopic</code></p></t
 d></tr></tbody></table></div><p>Make sure to add&#160;<strong><code>activemq-<em>&lt;version&gt;</em>.jar</code></strong> and&#160;<strong><code>spring-1.x.jar</code></strong> to your classpath. If the libraries are not in the classpath, you will get a&#160;<strong><code>ClassNotFoundException</code></strong> at runtime. If you get <strong><code>ClassNotFoundException</code></strong>, try printing out the classpath and check it is present. You can also run ActiveMQ with&#160;<strong><code>-verbose</code></strong> option to verify the jar was loaded correctly.</p><p><strong>Sample Code</strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">// Create a new intial context, which loads from jndi.properties file:
 javax.naming.Context ctx = new javax.naming.InitialContext();
-// lookup the connection factory
+
+// Lookup the connection factory:
 javax.jms.TopicConnectionFactory factory = (javax.jms.TopicConnectionFactory)ctx.lookup("ConnectionFactory");
-// create a new TopicConnection for pub/sub messaging
+
+// Create a new TopicConnection for pub/sub messaging:
 javax.jms.TopicConnection conn = factory.getTopicConnection();
-// lookup an existing topic
+
+// Lookup an existing topic:
 javax.jms.Topic mytopic = (javax.jms.Topic)ctx.lookup("MyTopic");
-// create a new TopicSession for the client
+
+// Create a new TopicSession for the client:
 javax.jms.TopicSession session = conn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
-// create a new subscriber to receive messages
+
+// Create a new subscriber to receive messages:
 javax.jms.TopicSubscriber subscriber = session.createSubscriber(mytopic);
 </pre>
-</div></div><p>Notice the name of the topic in the sample is "MyTopic". ActiveMQ will read the jndi.properties files and creates the topics and queues in a lazy fashion. The prefix topic and queue is stripped, so the jndi name begins after the prefix.</p><p>Once you have the jndi.properties edited and ready, it needs to be accessible to your application. The easiest way is to add jndi.properties to a jar file. When "new InitialContext()" is called, it will scan the resources and find the file. If you get "javax.naming.NamingException", it usually means the jndi.properties file is not accessible.</p><p>You can also try to create a new initial context using either an instance of properties file or a map. For example, the approach recommended by JMS specification will work just fine.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Example recommended by specification</p></th></tr><tr><td colspan="1" rowspan="1" cl
 ass="confluenceTd"><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>Notice the name of the topic in the sample is <strong><code>MyTopic</code></strong>. ActiveMQ will read the&#160;<strong><code>jndi.properties</code></strong> files and creates the topics and queues in a lazy fashion. The prefix topic and queue is stripped, so the JNDI name begins after the prefix.</p><p>Once you have the&#160;<strong><code>jndi.properties</code></strong> edited and ready, it needs to be accessible to your application. The easiest way is to add&#160;<strong><code>jndi.properties</code></strong> to a jar file. When&#160;<strong><code>new InitialContext()</code></strong> is called, it will scan the resources and find the file. If you get <strong><code>javax.naming.NamingException</code></strong>, it usually means the&#160;<strong><code>jndi.properties</code></strong> file is not accessible.</p><p>You can also try to create a new initial context using either an instance of properties file or a map. For example, the approach recommended by JMS specificati
 on will work just fine.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Example Recommended by Specification</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">Properties props = new Properties();
 props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
 props.setProperty(Context.PROVIDER_URL,"tcp://hostname:61616");
 javax.naming.Context ctx = new InitialContext(props);||
 </pre>
-</div></div></td></tr></tbody></table></div><p>If ActiveMQ is embedded within an EJB container, you will need to look at the containers documentation for the correct jndi values.</p><h3 id="JNDISupport-Dynamicallycreatingdestinations">Dynamically creating destinations</h3><p>For the easiest possible configuration with JNDI based programs, there are 2 dynamic contexts as follows</p><ul><li>dynamicQueues</li><li>dynamicTopics</li></ul><p>which allows you to lookup queues and topics using JNDI without any configuration.</p><p>e.g. if you use the following name to lookup into JNDI</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div></td></tr></tbody></table></div><p>If ActiveMQ is embedded within an EJB container, you will need to look at the containers documentation for the correct JNDI values.</p><h3 id="JNDISupport-DynamicallyCreatingDestinations">Dynamically Creating Destinations</h3><p>For the easiest possible configuration with JNDI based programs, there are two dynamic contexts, namely:</p><ul><li><strong><code>dynamicQueues</code></strong></li><li><strong><code>dynamicTopics</code></strong></li></ul><p>These allow you to lookup queues and topics using JNDI without any configuration.</p><p>For example, if you use the following name to lookup into JNDI:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">dynamicQueues/FOO.BAR
 </pre>
-</div></div><p>you will get back an ActiveMQQueue of the name "FOO.BAR".</p><p>This can be very handy if you can easily reconfigure the JNDI name to use to lookup something in JNDI, but don't want to have to double configure a jndi.properties to matchup.</p><h3 id="JNDISupport-Workingwithembeddedbrokers">Working with embedded brokers</h3><p>It is often useful to use an embedded broker in the same JVM as the JMS client. For this see <a shape="rect" href="how-do-i-embed-a-broker-inside-a-connection.html">How do I embed a Broker inside a Connection</a>.</p><p>If you want to use an embedded broker with your JNDI provider you can just use the <a shape="rect" href="vm-transport-reference.html">VM Transport</a> to connect to the broker in your URL. e.g. to create a purely in JVM broker use this URI</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>you will get back an&#160;<strong><code>ActiveMQQueue</code></strong> of the name <strong><code>FOO.BAR</code></strong>. This can be very handy if you can easily reconfigure the JNDI name to use to lookup something in JNDI, but don't want to have to double configure a&#160;<strong><code>jndi.properties</code></strong> to match.</p><h3 id="JNDISupport-WorkingWithEmbeddedBrokers">Working With Embedded Brokers</h3><p>It is often useful to use an embedded broker in the same JVM as the JMS client. For this see <a shape="rect" href="how-do-i-embed-a-broker-inside-a-connection.html">How do I embed a Broker inside a Connection</a>.</p><p>If you want to use an embedded broker with your JNDI provider you can just use the <a shape="rect" href="vm-transport-reference.html">VM Transport</a> to connect to the broker in your URL. e.g. to create a purely in JVM broker use this URI</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">vm://locahost
 </pre>
-</div></div><p>If you want to customize the broker use something like this</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>If you want to customize the broker use something like this:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">vm:broker:(tcp://localhost:61616)
 </pre>
-</div></div><p>More options are available in the <a shape="rect" href="vm-transport-reference.html">VM Transport Reference</a></p><h3 id="JNDISupport-ExampleJavacode">Example Java code</h3><p>Once you have configured JNDI on the classpath you can run any normal JMS application such as the following <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/incubator/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/demo/SimpleProducer.java">example</a>. Notice that the Java code just uses pure JMS APIs and is not in any way ActiveMQ specific</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>More options are available in the <a shape="rect" href="vm-transport-reference.html">VM Transport Reference</a></p><h3 id="JNDISupport-ExampleJavaCode">Example Java Code</h3><p>Once you have configured JNDI on the classpath you can run any normal JMS application such as the following <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/incubator/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/demo/SimpleProducer.java">example</a>. Notice that the Java code just uses pure JMS APIs and is not in any way ActiveMQ specific</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">/**
- * 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.
- */
-/**
  * The SimpleQueueSender class consists only of a main method,
  * which sends several messages to a queue.
  *
@@ -154,7 +143,7 @@ javax.naming.Context ctx = new InitialCo
  * a number after the queue name to send that number of messages.
  */
 package org.apache.activemq.demo;
-// START SNIPPET: demo
+
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
@@ -167,92 +156,104 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 /**
  * A simple polymorphic JMS producer which can work with Queues or Topics which
- * uses JNDI to lookup the JMS connection factory and destination
- * 
- * 
+ * uses JNDI to lookup the JMS connection factory and destination.
  */
 public final class SimpleProducer {
     private static final Logger LOG = LoggerFactory.getLogger(SimpleProducer.class);
-    private SimpleProducer() {
-    }
-    /**
+    
+    private SimpleProducer() {}
+
+   &#160;/**
      * @param args the destination name to send to and optionally, the number of
      *                messages to send
      */
     public static void main(String[] args) {
-        Context jndiContext = null;
-        ConnectionFactory connectionFactory = null;
-        Connection connection = null;
-        Session session = null;
-        Destination destination = null;
-        MessageProducer producer = null;
-        String destinationName = null;
+        Context jndiContext;
+        ConnectionFactory connectionFactory;
+        Connection connection;
+        Session session;
+        Destination destination;
+        MessageProducer producer;
+        String destinationName;
         final int numMsgs;
-        if ((args.length &lt; 1) || (args.length &gt; 2)) {
+
+       &#160;if ((args.length &lt; 1) || (args.length &gt; 2)) {
             LOG.info("Usage: java SimpleProducer &lt;destination-name&gt; [&lt;number-of-messages&gt;]");
             System.exit(1);
         }
-        destinationName = args[0];
+
+       &#160;destinationName = args[0];
         LOG.info("Destination name is " + destinationName);
+       
         if (args.length == 2) {
             numMsgs = (new Integer(args[1])).intValue();
-        } else {
+        } 
+        else {
             numMsgs = 1;
         }
+        
         /*
          * Create a JNDI API InitialContext object
          */
         try {
             jndiContext = new InitialContext();
-        } catch (NamingException e) {
+        } 
+        catch (NamingException e) {
             LOG.info("Could not create JNDI API context: " + e.toString());
             System.exit(1);
         }
-        /*
+
+       &#160;/*
          * Look up connection factory and destination.
          */
         try {
             connectionFactory = (ConnectionFactory)jndiContext.lookup("ConnectionFactory");
             destination = (Destination)jndiContext.lookup(destinationName);
-        } catch (NamingException e) {
+        } 
+        catch (NamingException e) {
             LOG.info("JNDI API lookup failed: " + e);
             System.exit(1);
         }
-        /*
+
+       &#160;/*
          * Create connection. Create session from connection; false means
          * session is not transacted. Create sender and text message. Send
          * messages, varying text slightly. Send end-of-messages message.
-         * Finally, close connection.
+         * Finally, close the connection.
          */
         try {
             connection = connectionFactory.createConnection();
             session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
             producer = session.createProducer(destination);
             TextMessage message = session.createTextMessage();
-            for (int i = 0; i &lt; numMsgs; i++) {
+           
+           &#160;for (int i = 0; i &lt; numMsgs; i++) {
                 message.setText("This is message " + (i + 1));
                 LOG.info("Sending message: " + message.getText());
                 producer.send(message);
             }
-            /*
+
+           &#160;/*
              * Send a non-text control message indicating end of messages.
              */
             producer.send(session.createMessage());
-        } catch (JMSException e) {
+        } 
+        catch (JMSException e) {
             LOG.info("Exception occurred: " + e);
-        } finally {
+        }
+        finally {
             if (connection != null) {
                 try {
                     connection.close();
-                } catch (JMSException e) {
-                }
+                } 
+                catch (JMSException ignored) {}
             }
         }
     }
 }
-// END SNIPPET: demo
 </pre>
 </div></div></div>
         </td>