[jboss-cvs] JBoss Messaging SVN: r6858 - in trunk: docs/user-manual/en/modules and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 18 18:53:40 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-05-18 18:53:40 -0400 (Mon, 18 May 2009)
New Revision: 6858

Added:
   trunk/examples/jms/embedded/
   trunk/examples/jms/embedded/build.xml
   trunk/examples/jms/embedded/readme.html
   trunk/examples/jms/embedded/src/
   trunk/examples/jms/embedded/src/org/
   trunk/examples/jms/embedded/src/org/jboss/
   trunk/examples/jms/embedded/src/org/jboss/jms/
   trunk/examples/jms/embedded/src/org/jboss/jms/example/
   trunk/examples/jms/embedded/src/org/jboss/jms/example/EmbeddedExample.java
Modified:
   trunk/.classpath
   trunk/docs/user-manual/en/modules/embedding-jbm.xml
   trunk/docs/user-manual/en/modules/large-messages.xml
   trunk/src/main/org/jboss/messaging/core/server/Messaging.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java
Log:
Embedded Chapter and Example

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2009-05-18 22:21:25 UTC (rev 6857)
+++ trunk/.classpath	2009-05-18 22:53:40 UTC (rev 6858)
@@ -30,6 +30,7 @@
 	<classpathentry kind="src" path="examples/jms/delayed-redelivery/src"/>
 	<classpathentry kind="src" path="examples/jms/divert/src"/>
 	<classpathentry kind="src" path="examples/jms/durable-subscription/src"/>
+	<classpathentry kind="src" path="examples/jms/embedded/src"/>
 	<classpathentry kind="src" path="examples/jms/expiry/src"/>
 	<classpathentry kind="src" path="examples/jms/http-transport/src"/>
 	<classpathentry kind="src" path="examples/jms/instantiate-connection-factory/src"/>

Modified: trunk/docs/user-manual/en/modules/embedding-jbm.xml
===================================================================
--- trunk/docs/user-manual/en/modules/embedding-jbm.xml	2009-05-18 22:21:25 UTC (rev 6857)
+++ trunk/docs/user-manual/en/modules/embedding-jbm.xml	2009-05-18 22:53:40 UTC (rev 6858)
@@ -60,8 +60,134 @@
     </section>
     <section>
         <title>Dependency Frameworks</title>
-        <para>You may also choose to use a dependency injection framework such as JBoss Micro
-            Container or Spring.</para>
-        <para>TODO</para>
+        <para>You may also choose to use a dependency injection framework such as <trademark>JBoss
+                Micro Container</trademark> or <trademark>Spring Framework</trademark>.</para>
+        <para>JBoss Messaging standalone uses JBoss Micro Container as the injection framework.
+                <literal>JBMBootstrapServer</literal> and <literal>jbm-jboss-beans.xml</literal>
+            which are part of the JBoss Messaging distribution provide a very complete
+            implementation of what's needed to bootstrap the server using JBoss Micro Container. </para>
+        <para>When using JBoss Micro Container, you need to provide a XML with the four objects
+            required to instantiate a Server:</para>
+        <itemizedlist>
+            <listitem>
+                <para>The configuration. We will use ConfigurationImpl</para>
+            </listitem>
+            <listitem>
+                <para>A MBeanServer required by management.</para>
+            </listitem>
+            <listitem>
+                <para>The Security Manager</para>
+            </listitem>
+            <listitem>
+                <para>And the Messaging Server itself.</para>
+            </listitem>
+        </itemizedlist>
+        <para>A very basic XML Bean declaration for the JBoss Micro Container would be:</para>
+        <programlisting>&lt;?xml version="1.0" encoding="UTF-8"?>
+
+&lt;deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+    &lt;bean name="MBeanServer" class="javax.management.MBeanServer">
+      &lt;constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   &lt;/bean> 
+
+   &lt;!-- The core configuration -->
+   &lt;bean name="Configuration" 
+         class="org.jboss.messaging.core.config.impl.FileConfiguration">
+   &lt;/bean>
+
+	&lt;!-- The security manager -->
+   &lt;bean name="JBMSecurityManager" 
+       class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+      &lt;start ignored="true"/>
+      &lt;stop ignored="true"/>
+   &lt;/bean>
+
+	&lt;!-- The core server -->
+   &lt;bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl">
+     &lt;start ignored="true"/>
+      &lt;stop ignored="true"/>  
+      &lt;constructor>
+         &lt;parameter>
+            &lt;inject bean="Configuration"/>
+         &lt;/parameter>
+         &lt;parameter>
+            &lt;inject bean="MBeanServer"/>
+         &lt;/parameter>
+         &lt;parameter>
+            &lt;inject bean="JBMSecurityManager"/>
+         &lt;/parameter>        
+      &lt;/constructor>         
+   &lt;/bean>
+   &lt;/deployment></programlisting>
+        <para><literal>JBMBootstrapServer</literal> provides an easy encapsulation of JBoss Micro
+            Container.</para>
+        <programlisting>JBMBootstrapServer bootStrap = new JBMBootstrapServer(new String[] {"jbm-jboss-beans.xml"});
+        bootStrap.run();</programlisting>
     </section>
+    <section>
+        <title>Connecting to the Embedeed JBoss Messaging</title>
+        <para>There is no special requirement on connecting to an Embedded JBoss Messaging. As you
+            are managing POJOs directly you just instantiate the factories.</para>
+        <section>
+            <title>Core API</title>
+            <para>If using the core API, just create the <literal>ClientSessionFactory</literal> and
+                use the regular core API.</para>
+            <programlisting>ClientSessionFactory nettyFactory =  new ClientSessionFactoryImpl(
+                                     new TransportConfiguration(InVMConnectorFactory.class.getName()), null);
+ClientSession session = factory.createSession(false, true, true);
+session.createQueue("example", "example", true);
+
+ClientProducer producer = session.createProducer("example");
+ClientMessage message = session.createClientMessage(true);
+
+message.getBody().writeString("Hello");
+
+producer.send(message);
+
+session.start();
+
+ClientConsumer consumer = session.createConsumer("example");
+
+ClientMessage msgReceived = consumer.receive();
+System.out.println("message = " + msgReceived.getBody().readString());
+
+session.close();
+            </programlisting>
+        </section>
+        <section>
+            <title>JMS API</title>
+            <para>Connection on an Embedded JBoss Messaging through JMS is also simple. Just
+                instantiate <literal>JBossConnectionFactory</literal> directly. The following
+                example ilustrates that.</para>
+            <programlisting>JBossConnectionFactory cf = new JBossConnectionFactory(
+                            new TransportConfiguration(InVMConnectorFactory.class.getName()));
+
+Connection conn = cf.createConnection();
+
+conn.start();
+
+Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+MessageProducer prod = sess.createProducer(queue);
+
+TextMessage msg = sess.createTextMessage("Hello!");
+
+prod.send(msg);
+
+sess.commit();
+
+MessageConsumer consumer = sess.createConsumer(queue);
+
+TextMessage txtmsg = (TextMessage)consumer.receive();
+
+System.out.println("Msg = " + txtmsg.getText());
+
+sess.commit();
+
+conn.close();
+            </programlisting>
+        </section>
+    </section>
 </chapter>

Modified: trunk/docs/user-manual/en/modules/large-messages.xml
===================================================================
--- trunk/docs/user-manual/en/modules/large-messages.xml	2009-05-18 22:21:25 UTC (rev 6857)
+++ trunk/docs/user-manual/en/modules/large-messages.xml	2009-05-18 22:53:40 UTC (rev 6858)
@@ -39,7 +39,8 @@
             <title>Using Core API</title>
             <para>If the JBoss Messaging Core API is used, the minimal large message size is
                 specified by <literal>ClientSessionFactory.setMinLargeMessageSize</literal>.</para>
-            <programlisting>ClientSessionFactory factory = ....;
+            <programlisting>ClientSessionFactory factory = new ClientSessionFactoryImpl(new 
+                        TransportConfiguration(NettyConnectorFactory.class.getName()), null);
 factory.setMinLargeMessageSize(25000);</programlisting>
             <para><xref linkend="configuring-transports.client.side"/> will provide more information
                 on how to instantiate the session factory.</para>


Property changes on: trunk/examples/jms/embedded
___________________________________________________________________
Name: svn:ignore
   + logs


Added: trunk/examples/jms/embedded/build.xml
===================================================================
--- trunk/examples/jms/embedded/build.xml	                        (rev 0)
+++ trunk/examples/jms/embedded/build.xml	2009-05-18 22:53:40 UTC (rev 6858)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+      <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+      ]>
+
+<!-- =========================================================================================== -->
+<!--                                                                                             -->
+<!-- JBoss, Home of Professional Open Source                                                     -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated                        -->
+<!-- by the @authors tag. See the copyright.txt in the distribution for a                        -->
+<!-- full listing of individual contributors.                                                    -->
+<!--                                                                                             -->
+<!-- This is free software; you can redistribute it and/or modify it                             -->
+<!-- under the terms of the GNU Lesser General Public License as                                 -->
+<!-- published by the Free Software Foundation; either version 2.1 of                            -->
+<!-- the License, or (at your option) any later version.                                         -->
+<!--                                                                                             -->
+<!-- This software is distributed in the hope that it will be useful,                            -->
+<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of                              -->
+<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU                            -->
+<!-- Lesser General Public License for more details.                                             -->
+<!--                                                                                             -->
+<!-- You should have received a copy of the GNU Lesser General Public                            -->
+<!-- License along with this software; if not, write to the Free                                 -->
+<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA                          -->
+<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org.                                    -->
+<!--                                                                                             -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging Embedded Example">
+
+   <import file="../common/build.xml"/>
+
+   <target name="run">   	
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.EmbeddedExample"/>
+         <!-- We limit the client to running in only 50MB of RAM -->
+     	   <param name="java-min-memory" value="50M"/>
+     	   <param name="java-max-memory" value="50M"/>
+      </antcall>
+   </target>
+</project>

Added: trunk/examples/jms/embedded/readme.html
===================================================================
--- trunk/examples/jms/embedded/readme.html	                        (rev 0)
+++ trunk/examples/jms/embedded/readme.html	2009-05-18 22:53:40 UTC (rev 6858)
@@ -0,0 +1,89 @@
+<html>
+  <head>
+    <title>JBoss Messaging Embedded Example</title>
+    <link rel="stylesheet" type="text/css" href="../common/common.css">
+  </head>
+  <body>
+     <h1>Embedded Example</h1>
+     <br>
+     <p>This examples shows how to setup and run JBoss Messaging embedded.</p>
+     <p>JBoss Messaging was designed to use POJOs (Plain Old Java Objects), what makes embedding JBoss Messaging as simple as instantiating a few objects.</p>
+     <p>JBoss Messaging Embedded could be used from very simple use cases with only InVM support to very complex cases with clustering, persistence and fail over.</p>
+     <br>
+     <h2>Example step-by-step</h2>     
+     <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+     <p>In this we don't use any configuration files. (Everything is embedded). We simply instantiate ConfigurationImpl, MessagingServer, start it and operate on JMS regularly</p>
+     <br>
+     <ol>
+        <li>Create the Configuration, and set the properties accordingly</li>
+        <pre>
+         <code>Configuration configuration = new ConfigurationImpl();</code>
+         <code>configuration.setEnablePersistence(false);</code>
+         <code>configuration.setSecurityEnabled(false);</code></pre>
+         
+        <li>Create and start the server</li>
+        <pre>
+           <code>MessagingServer server = Messaging.newMessagingServer(configuration);</code>
+           <code>server.start();</code></pre>
+
+        <li>As we are not using a JNDI environment we instantiate the objects directly</li>
+        <pre>
+           <code>Queue queue = new JBossQueue("exampleQueue");</code>
+           <code>JBossConnectionFactory cf = new JBossConnectionFactory (new TransportConfiguration(InVMConnectorFactory.class.getName()));</code>
+        </pre>
+
+        <li>Create a JMS Destination by using the Core API</li>
+        <pre>
+           <code>
+         ClientSession coreSession = cf.getCoreFactory().createSession(false, false, false);
+         coreSession.createQueue("jms.queue.exampleQueue", "jms.queue.exampleQueue", true);
+         coreSession.close();</code>
+        </pre>
+
+        <li>Create the JMS objects</li>
+        <pre>
+           <code>
+            connection = cf.createConnection();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageProducer producer = session.createProducer(queue);</code>
+        </pre>
+
+        <li>Create and send a TextMessage</li>
+        <pre><code>
+            TextMessage message = session.createTextMessage("Hello sent at " + new Date());
+            System.out.println("Sending the message.");
+            producer.send(message);</code></pre>
+
+        <li>Create the message consumer and start the connection</li>
+        <pre><code>
+            MessageConsumer messageConsumer = session.createConsumer(queue);
+            connection.start();</code></pre>
+
+        <li>Receive the message</li>
+        <pre><code>
+            TextMessage messageReceived = (TextMessage)messageConsumer.receive(1000);
+            System.out.println("Received TextMessage:" + messageReceived.getText());</code></pre>
+
+        <li>Be sure to close our resources!</li>
+
+        <pre>
+           <code>
+           finally
+           {
+              if (connection != null)
+              {
+                 connection.close();
+              }
+           }</code>
+        </pre>
+
+        <li>Stop the server</li>
+
+        <pre>
+           <code>
+           server.stop();
+		   </code>
+        </pre>
+     </ol>
+  </body>
+</html>
\ No newline at end of file

Added: trunk/examples/jms/embedded/src/org/jboss/jms/example/EmbeddedExample.java
===================================================================
--- trunk/examples/jms/embedded/src/org/jboss/jms/example/EmbeddedExample.java	                        (rev 0)
+++ trunk/examples/jms/embedded/src/org/jboss/jms/example/EmbeddedExample.java	2009-05-18 22:53:40 UTC (rev 6858)
@@ -0,0 +1,118 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+   * by the @authors tag. See the copyright.txt in the distribution for a
+   * full listing of individual contributors.
+   *
+   * This is free software; you can redistribute it and/or modify it
+   * under the terms of the GNU Lesser General Public License as
+   * published by the Free Software Foundation; either version 2.1 of
+   * the License, or (at your option) any later version.
+   *
+   * This software is distributed in the hope that it will be useful,
+   * but WITHOUT ANY WARRANTY; without even the implied warranty of
+   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   * Lesser General Public License for more details.
+   *
+   * You should have received a copy of the GNU Lesser General Public
+   * License along with this software; if not, write to the Free
+   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+   */
+package org.jboss.jms.example;
+
+import java.util.Date;
+
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+
+/**
+ * This example demonstrates how to run JBoss Messaging embedded
+ * 
+ * @author <a href="clebert.suconic at jboss.com">Clebert Suconic</a>
+ */
+public class EmbeddedExample
+{
+
+   public static void main(String[] args)
+   {
+      try
+      {
+         
+         // Step 1. Create the Configuration, and set the properties accordingly
+         Configuration configuration = new ConfigurationImpl();
+         configuration.setEnablePersistence(false);
+         configuration.setSecurityEnabled(false);
+         
+         // Step 2. Create and start the server
+         MessagingServer server = Messaging.newMessagingServer(configuration);
+         server.start();
+   
+   
+         // Step 3. As we are not using a JNDI environment we instantiate the objects directly
+         Queue queue = new JBossQueue("exampleQueue");
+         JBossConnectionFactory cf = new JBossConnectionFactory (new TransportConfiguration(InVMConnectorFactory.class.getName()));
+         
+         // Step 4. Create a JMS Destination by using the Core API
+         ClientSession coreSession = cf.getCoreFactory().createSession(false, false, false);
+         coreSession.createQueue("jms.queue.exampleQueue", "jms.queue.exampleQueue", true);
+         coreSession.close();
+         
+         
+         Connection connection = null;
+   
+         try
+         {
+   
+            // Step 5. Create the JMS objects
+            connection = cf.createConnection();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageProducer producer = session.createProducer(queue);
+   
+            // Step 6. Create and send a TextMessage
+            TextMessage message = session.createTextMessage("Hello sent at " + new Date());
+            System.out.println("Sending the message.");
+            producer.send(message);
+
+            // Step 7. Create the message consumer and start the connection
+            MessageConsumer messageConsumer = session.createConsumer(queue);
+            connection.start();
+   
+            // Step 8. Receive the message. 
+            TextMessage messageReceived = (TextMessage)messageConsumer.receive(1000);
+            System.out.println("Received TextMessage:" + messageReceived.getText());
+         }
+         finally
+         {
+            // Step 9. Be sure to close our resources!
+            if (connection != null)
+            {
+               connection.close();
+            }
+            
+            // Step 10. Stop the server
+            server.stop();
+         }
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         System.exit(-1);
+      }
+   }
+
+}

Modified: trunk/src/main/org/jboss/messaging/core/server/Messaging.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Messaging.java	2009-05-18 22:21:25 UTC (rev 6857)
+++ trunk/src/main/org/jboss/messaging/core/server/Messaging.java	2009-05-18 22:53:40 UTC (rev 6858)
@@ -59,7 +59,7 @@
 
    public static MessagingServer newMessagingServer(final Configuration config)
    {
-      return newMessagingServer(config, true);
+      return newMessagingServer(config, config.isEnablePersistence());
    }
 
    public static MessagingServer newMessagingServer(final Configuration config,

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java	2009-05-18 22:21:25 UTC (rev 6857)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java	2009-05-18 22:53:40 UTC (rev 6858)
@@ -77,6 +77,11 @@
       sessionFactory = new ClientSessionFactoryImpl();
    }
 
+   public JBossConnectionFactory(final ClientSessionFactory sessionFactory)
+   {
+      this.sessionFactory = sessionFactory;
+   }
+
    public JBossConnectionFactory(final String discoveryAddress, final int discoveryPort)
    {
       sessionFactory = new ClientSessionFactoryImpl(discoveryAddress, discoveryPort);




More information about the jboss-cvs-commits mailing list