activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r859120 - in /websites/production/activemq/content: cache/main.pageCache jndi-support.html
Date Fri, 19 Apr 2013 14:22:35 GMT
Author: buildbot
Date: Fri Apr 19 14:22:35 2013
New Revision: 859120

Log:
Production update by buildbot for activemq

Modified:
    websites/production/activemq/content/cache/main.pageCache
    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/jndi-support.html
==============================================================================
--- websites/production/activemq/content/jndi-support.html (original)
+++ websites/production/activemq/content/jndi-support.html Fri Apr 19 14:22:35 2013
@@ -78,14 +78,35 @@
 
 <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-core/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="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException:
Index: 20, Size: 20</span> </div>
+<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" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-none">
+java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
+
+# 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
+# should appear as. 
+#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
+
+# 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]
+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" title="How do I
embed a Broker inside a Connection">how to embed a broker in a connection</a> for
more details.</p>
 
 <h3><a shape="rect" name="JNDISupport-ActiveMQJNDITutorial"></a>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="http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/jndi.properties?view=markup">http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/jndi.properties?view=markup</a>.
Before we proceed, here are the properties.</p>
+<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="http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/resources/jndi.properties?view=markup">http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/resources/jndi.properties?view=markup</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"> Name </th><th colspan="1" rowspan="1" class="confluenceTh">
Value </th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">
java.naming.factory.initial </td><td colspan="1" rowspan="1" class="confluenceTd">
org.apache.activemq.jndi.ActiveMQInitialContextFactory </td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"> java.naming.provider.url </td><td
colspan="1" rowspan="1" class="confluenceTd"> tcp://hostname:61616 </td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"> topic.MyTopic </td><td colspan="1"
rowspan="1" class="confluenceTd"> example.MyTopic </td></tr></tbody></table>
 </div>
@@ -165,8 +186,119 @@ vm:broker:(tcp:<span class="code-comment
 
 <h3><a shape="rect" name="JNDISupport-ExampleJavacode"></a>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-core/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="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException:
Index: 20, Size: 20</span> </div>
+<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" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+<span class="code-keyword">import</span> javax.jms.Connection;
+<span class="code-keyword">import</span> javax.jms.ConnectionFactory;
+<span class="code-keyword">import</span> javax.jms.Destination;
+<span class="code-keyword">import</span> javax.jms.JMSException;
+<span class="code-keyword">import</span> javax.jms.MessageProducer;
+<span class="code-keyword">import</span> javax.jms.Session;
+<span class="code-keyword">import</span> javax.jms.TextMessage;
+<span class="code-keyword">import</span> javax.naming.Context;
+<span class="code-keyword">import</span> javax.naming.InitialContext;
+<span class="code-keyword">import</span> javax.naming.NamingException;
+
+<span class="code-keyword">import</span> org.slf4j.Logger;
+<span class="code-keyword">import</span> 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
+ * 
+ * 
+ */
+<span class="code-keyword">public</span> <span class="code-keyword">final</span>
class SimpleProducer {
+
+    <span class="code-keyword">private</span> <span class="code-keyword">static</span>
<span class="code-keyword">final</span> Logger LOG = LoggerFactory.getLogger(SimpleProducer.class);
+
+    <span class="code-keyword">private</span> SimpleProducer() {
+    }
+
+    /**
+     * @param args the destination name to send to and optionally, the number of
+     *                messages to send
+     */
+    <span class="code-keyword">public</span> <span class="code-keyword">static</span>
void main(<span class="code-object">String</span>[] args) {
+        Context jndiContext = <span class="code-keyword">null</span>;
+        ConnectionFactory connectionFactory = <span class="code-keyword">null</span>;
+        Connection connection = <span class="code-keyword">null</span>;
+        Session session = <span class="code-keyword">null</span>;
+        Destination destination = <span class="code-keyword">null</span>;
+        MessageProducer producer = <span class="code-keyword">null</span>;
+        <span class="code-object">String</span> destinationName = <span class="code-keyword">null</span>;
+        <span class="code-keyword">final</span> <span class="code-object">int</span>
numMsgs;
+
+        <span class="code-keyword">if</span> ((args.length &lt; 1) || (args.length
&gt; 2)) {
+            LOG.info(<span class="code-quote">"Usage: java SimpleProducer &lt;destination-name&gt;
[&lt;number-of-messages&gt;]"</span>);
+            <span class="code-object">System</span>.exit(1);
+        }
+        destinationName = args[0];
+        LOG.info(<span class="code-quote">"Destination name is "</span> + destinationName);
+        <span class="code-keyword">if</span> (args.length == 2) {
+            numMsgs = (<span class="code-keyword">new</span> <span class="code-object">Integer</span>(args[1])).intValue();
+        } <span class="code-keyword">else</span> {
+            numMsgs = 1;
+        }
+
+        /*
+         * Create a JNDI API InitialContext object
+         */
+        <span class="code-keyword">try</span> {
+            jndiContext = <span class="code-keyword">new</span> InitialContext();
+        } <span class="code-keyword">catch</span> (NamingException e) {
+            LOG.info(<span class="code-quote">"Could not create JNDI API context: "</span>
+ e.toString());
+            <span class="code-object">System</span>.exit(1);
+        }
+
+        /*
+         * Look up connection factory and destination.
+         */
+        <span class="code-keyword">try</span> {
+            connectionFactory = (ConnectionFactory)jndiContext.lookup(<span class="code-quote">"ConnectionFactory"</span>);
+            destination = (Destination)jndiContext.lookup(destinationName);
+        } <span class="code-keyword">catch</span> (NamingException e) {
+            LOG.info(<span class="code-quote">"JNDI API lookup failed: "</span>
+ e);
+            <span class="code-object">System</span>.exit(1);
+        }
+
+        /*
+         * Create connection. Create session from connection; <span class="code-keyword">false</span>
means
+         * session is not transacted. Create sender and text message. Send
+         * messages, varying text slightly. Send end-of-messages message.
+         * Finally, close connection.
+         */
+        <span class="code-keyword">try</span> {
+            connection = connectionFactory.createConnection();
+            session = connection.createSession(<span class="code-keyword">false</span>,
Session.AUTO_ACKNOWLEDGE);
+            producer = session.createProducer(destination);
+            TextMessage message = session.createTextMessage();
+            <span class="code-keyword">for</span> (<span class="code-object">int</span>
i = 0; i &lt; numMsgs; i++) {
+                message.setText(<span class="code-quote">"This is message "</span>
+ (i + 1));
+                LOG.info(<span class="code-quote">"Sending message: "</span>
+ message.getText());
+                producer.send(message);
+            }
+
+            /*
+             * Send a non-text control message indicating end of messages.
+             */
+            producer.send(session.createMessage());
+        } <span class="code-keyword">catch</span> (JMSException e) {
+            LOG.info(<span class="code-quote">"Exception occurred: "</span> +
e);
+        } <span class="code-keyword">finally</span> {
+            <span class="code-keyword">if</span> (connection != <span class="code-keyword">null</span>)
{
+                <span class="code-keyword">try</span> {
+                    connection.close();
+                } <span class="code-keyword">catch</span> (JMSException e) {
+                }
+            }
+        }
+    }
+}
+
+</pre>
+</div></div>
           </div>
         </td>
         <td valign="top">



Mime
View raw message