[jboss-cvs] JBoss Messaging SVN: r6561 - in trunk/examples/jms: no-consumer-buffering and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 24 12:16:49 EDT 2009


Author: timfox
Date: 2009-04-24 12:16:49 -0400 (Fri, 24 Apr 2009)
New Revision: 6561

Added:
   trunk/examples/jms/no-consumer-buffering/
   trunk/examples/jms/no-consumer-buffering/build.xml
   trunk/examples/jms/no-consumer-buffering/readme.html
   trunk/examples/jms/no-consumer-buffering/server0/
   trunk/examples/jms/no-consumer-buffering/server0/client-jndi.properties
   trunk/examples/jms/no-consumer-buffering/server0/jbm-configuration.xml
   trunk/examples/jms/no-consumer-buffering/server0/jbm-jms.xml
   trunk/examples/jms/no-consumer-buffering/server0/jbm-queues.xml
   trunk/examples/jms/no-consumer-buffering/server0/jbm-standalone-beans.xml
   trunk/examples/jms/no-consumer-buffering/server0/jbm-users.xml
   trunk/examples/jms/no-consumer-buffering/src/
   trunk/examples/jms/no-consumer-buffering/src/org/
   trunk/examples/jms/no-consumer-buffering/src/org/jboss/
   trunk/examples/jms/no-consumer-buffering/src/org/jboss/jms/
   trunk/examples/jms/no-consumer-buffering/src/org/jboss/jms/example/
   trunk/examples/jms/no-consumer-buffering/src/org/jboss/jms/example/NoConsumerBufferingExample.java
Log:
no consumer buffering example


Property changes on: trunk/examples/jms/no-consumer-buffering
___________________________________________________________________
Name: svn:ignore
   + build
logs


Added: trunk/examples/jms/no-consumer-buffering/build.xml
===================================================================
--- trunk/examples/jms/no-consumer-buffering/build.xml	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/build.xml	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,48 @@
+<?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 JMS No Consumer Buffering Example">
+
+   <import file="../common/build.xml"/>
+
+   <target name="run">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.NoConsumerBufferingExample"/>
+      </antcall>
+   </target>
+
+   <target name="runRemote">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.NoConsumerBufferingExample"/>
+         <param name="jbm.example.runServer" value="false"/>
+      </antcall>
+   </target>
+
+</project>
\ No newline at end of file

Added: trunk/examples/jms/no-consumer-buffering/readme.html
===================================================================
--- trunk/examples/jms/no-consumer-buffering/readme.html	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/readme.html	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,180 @@
+<html>
+  <head>
+    <title>JBoss Messaging No Consumer Buffering Example</title>
+    <link rel="stylesheet" type="text/css" href="../common/common.css">
+  </head>
+  <body>
+     <h1>JBoss Messaging <br>No Consumer Buffering Example</h1>
+     <br><br>
+     <p>By default, JBoss Messaging consumers buffer messages from the server in a client side buffer
+     before you actually receive them on the client side.</p>
+     <p>This improves performance since otherwise every time you called receive() or had processed the last
+     message in a MessageListener onMessage() method, the JBoss Messaging client would have to go the
+     server to request the next message, which would then get sent to the client side, if one was available.</p>
+     <p>This would involve a network round trip for every message and really reduce performance.</p>
+     <p>Therefore, by default, JBoss Messaging pre-fetches messages into a buffer on each consumer. The total maximum size of
+     messages in bytes that will be buffered on each consumer is determined by the <code>consumer-window-size</code>
+     parameter on the connection factory.</p>
+     <p>In some cases it is not desirable to buffer any messages on the client side consumer.</p>
+     <p>An example would be an order queue which had multiple consumers that processed orders from the queue.
+     Each order takes a significant time to process, but each one should be processed in a timely fashion.</p>
+     <p>If orders were buffered in each consumer, and a new consumer was added that consumer would not be able
+     to process orders which were already in the client side buffer of another consumer.</p>
+     <p>To turn off client side buffering of messages, set <code>consumer-window-size</code> to zero.</p>
+     
+     <p>With JBoss Messaging you can specify a maximum consume rate at which a JMS MessageConsumer will consume messages.
+     This can be specified when creating or deploying the connection factory. See <code>jbm-jms.xml</code></p>     
+     <h2>Example step-by-step</h2>
+     <p>In this example we specify a <code>consumer-window-size</code> of <code>0</code> bytes in the <code>jbm-jms.xml</code>
+     file when deploying the connection factory:</p>
+     <pre>
+     <code>
+   &lt;connection-factory name="ConnectionFactory"&gt;
+      &lt;connector-ref connector-name="netty-connector"/&gt;
+      &lt;entries&gt;
+         &lt;entry name="ConnectionFactory"/&gt;       
+      &lt;/entries&gt;
+      
+      &lt;!-- We set the consumer window size to 0, which means messages are not buffered at all
+      on the client side --&gt;
+      &lt;consumer-window-size&gt;0&lt;/consumer-window-size&gt;
+      
+   &lt;/connection-factory&gt;
+     </code>
+     </pre>
+     <p>We create a consumer on a queue and send 10 messages to it. We then create another consumer on
+     the same queue.</p>
+     <p>We then consume messages from each consumer in a semi-random order. We note that the messages
+     are consumed in the order they were sent.</p>
+     <p>If the messages had been buffered in each consumer they would not be available to be consumed
+     in an order determined afer delivery.</p>    
+     <br>
+     <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+     <br>
+     <ol>
+        <li>Create an initial context to perform the JNDI lookup.</li>
+        <pre>
+           <code>initialContext = getContext(0);</code>
+        </pre>
+
+        <li>Perfom a lookup on the queue</li>
+        <pre>
+           <code>Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");</code>
+        </pre>
+
+        <li>Perform a lookup on the Connection Factory</li>
+        <pre>
+           <code>ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");</code>
+        </pre>
+
+        <li>Create a JMS Connection</li>
+        <pre>
+           <code>connection = cf.createConnection();</code>
+        </pre>
+
+        <li>Create a JMS Session</li>
+        <pre>
+           <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+        </pre>
+
+        <li>Create a JMS MessageProducer</li>
+        <pre>
+          <code>MessageProducer producer = session.createProducer(queue);</code>
+        </pre>
+
+        <li>Create a JMS MessageConsumer</li>
+        <pre>
+           <code>MessageConsumer consumer1 = session.createConsumer(queue);</code>
+        </pre>
+        
+        <li>Start the connection</li>
+        
+        <pre>
+           <code>
+     connection.start();
+           </code>
+        </pre>
+           
+
+        <li>Send 10 messages to the queue</li>
+        <pre>
+           <code>
+     final int numMessages = 10;
+         
+     for (int i = 0; i < numMessages; i++)
+     {
+        TextMessage message = session.createTextMessage("This is text message: " + i);
+
+        producer.send(message);
+     }           
+           </code>
+        </pre>
+        
+        <li>Create another JMS MessageConsumer on the same queue.</li>
+        <pre>
+           <code>MessageConsumer consumer2 = session.createConsumer(queue);</code>
+        </pre>
+        
+        <li>Consume three messages from consumer2</li>
+        
+        <pre>
+           <code>
+   for (int i = 0; i < 3; i++)
+   {         
+      TextMessage message = (TextMessage)consumer2.receive(2000);
+            
+      System.out.println("Consumed message from consumer2: " + message.getText());
+   }    
+           </code>
+        </pre>
+        
+        <li>Consume five messages from consumer1</li>
+        
+        <pre>
+           <code>
+   for (int i = 0; i < 5; i++)
+   {         
+      TextMessage message = (TextMessage)consumer1.receive(2000);
+            
+      System.out.println("Consumed message from consumer1: " + message.getText());
+   }    
+           </code>
+        </pre> 
+               
+        <li>Consume two more messages from consumer2</li>
+        
+        <pre>
+           <code>
+   for (int i = 0; i < 2; i++)
+   {         
+      TextMessage message = (TextMessage)consumer1.receive(2000);
+            
+      System.out.println("Consumed message from consumer2: " + message.getText());
+   }    
+           </code>
+        </pre>                
+        
+
+        <li>Be sure to close our resources!</li>
+
+        <pre>
+           <code>
+           finally
+           {
+              if (initialContext != null)
+              {
+                initialContext.close();
+              }
+              
+              if (connection != null)
+              {
+                 connection.close();
+              }
+           }</code>
+        </pre>
+
+
+
+     </ol>
+  </body>
+</html>
\ No newline at end of file


Property changes on: trunk/examples/jms/no-consumer-buffering/server0
___________________________________________________________________
Name: svn:ignore
   + data
logs


Added: trunk/examples/jms/no-consumer-buffering/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/no-consumer-buffering/server0/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/server0/client-jndi.properties	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/no-consumer-buffering/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/no-consumer-buffering/server0/jbm-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/server0/jbm-configuration.xml	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,29 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd">
+   <configuration>
+
+      <!-- Connectors -->
+
+      <connectors>
+         <connector name="netty-connector">
+            <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+            <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+         </connector>
+      </connectors>
+      
+      <!-- Acceptors -->
+      <acceptors>
+         <acceptor name="netty-acceptor">
+            <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+            <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+         </acceptor>
+      </acceptors>
+
+      <!-- Other config -->
+
+      <journal-min-files>2</journal-min-files>
+
+   </configuration>
+
+</deployment>

Added: trunk/examples/jms/no-consumer-buffering/server0/jbm-jms.xml
===================================================================
--- trunk/examples/jms/no-consumer-buffering/server0/jbm-jms.xml	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/server0/jbm-jms.xml	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,22 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd ">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connector-ref connector-name="netty-connector"/>
+      <entries>
+         <entry name="ConnectionFactory"/>       
+      </entries>
+      
+      <!-- We set the consumer window size to 0, which means messages are not buffered at all
+      on the client side -->
+      <consumer-window-size>0</consumer-window-size>
+      
+   </connection-factory>
+
+   <!--the queue used by the example-->
+   <queue name="exampleQueue">
+      <entry name="/queue/exampleQueue"/>
+   </queue>
+
+</deployment>

Added: trunk/examples/jms/no-consumer-buffering/server0/jbm-queues.xml
===================================================================
--- trunk/examples/jms/no-consumer-buffering/server0/jbm-queues.xml	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/server0/jbm-queues.xml	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,15 @@
+<settings xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-queues.xsd ">
+
+   <!--security for example queue-->
+   <security match="jms.queue.exampleQueue">
+      <permission type="createDurableQueue" roles="guest"/>
+      <permission type="deleteDurableQueue" roles="guest"/>
+      <permission type="createTempQueue" roles="guest"/>
+      <permission type="deleteTempQueue" roles="guest"/>
+      <permission type="consume" roles="guest"/>
+      <permission type="send" roles="guest"/>
+   </security>
+
+</settings>

Added: trunk/examples/jms/no-consumer-buffering/server0/jbm-standalone-beans.xml
===================================================================
--- trunk/examples/jms/no-consumer-buffering/server0/jbm-standalone-beans.xml	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/server0/jbm-standalone-beans.xml	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">1099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">1098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+   
+   <!-- MBean server -->
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+
+   <!-- The core configuration -->
+   <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+   <!-- The security manager -->
+   <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+
+   <!-- The core server -->
+   <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl"> 
+      <start ignored="true"/>
+      <stop ignored="true"/>
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="JBMSecurityManager"/>
+         </parameter>        
+      </constructor>         
+   </bean>
+   
+   <!-- The JMS server -->
+   <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+      <constructor>         
+         <parameter>
+            <inject bean="MessagingServer"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+</deployment>

Added: trunk/examples/jms/no-consumer-buffering/server0/jbm-users.xml
===================================================================
--- trunk/examples/jms/no-consumer-buffering/server0/jbm-users.xml	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/server0/jbm-users.xml	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-users.xsd ">
+   <!-- the default user.  this is used where username is null-->
+   <defaultuser name="guest" password="guest">
+      <role name="guest"/>
+   </defaultuser>
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/no-consumer-buffering/src/org/jboss/jms/example/NoConsumerBufferingExample.java
===================================================================
--- trunk/examples/jms/no-consumer-buffering/src/org/jboss/jms/example/NoConsumerBufferingExample.java	                        (rev 0)
+++ trunk/examples/jms/no-consumer-buffering/src/org/jboss/jms/example/NoConsumerBufferingExample.java	2009-04-24 16:16:49 UTC (rev 6561)
@@ -0,0 +1,139 @@
+/*
+   * 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 javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * This example demonstrates how JBoss Messaging consumers can be configured to not buffer any messages from
+ * the server.
+ *
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ */
+public class NoConsumerBufferingExample extends JMSExample
+{
+   public static void main(String[] args)
+   {
+      new NoConsumerBufferingExample().run(args);
+   }
+
+   public boolean runExample() throws Exception
+   {
+      Connection connection = null;
+      InitialContext initialContext = null;
+      try
+      {
+         // Step 1. Create an initial context to perform the JNDI lookup.
+         initialContext = getContext(0);
+
+         // Step 2. Perfom a lookup on the queue
+         Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
+
+         // Step 3. Perform a lookup on the Connection Factory
+         ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+
+         // Step 4. Create a JMS Connection
+         connection = cf.createConnection();
+
+         // Step 5. Create a JMS Session
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Step 6. Create a JMS Message Producer
+         MessageProducer producer = session.createProducer(queue);
+         
+         // Step 7. Create a JMS MessageConsumer
+         
+         MessageConsumer consumer1 = session.createConsumer(queue);
+         
+         // Step 8. Start the connection
+         
+         connection.start();
+         
+         // Step 9. Send 10 messages to the queue
+         
+         final int numMessages = 10;
+         
+         for (int i = 0; i < numMessages; i++)
+         {
+            TextMessage message = session.createTextMessage("This is text message: " + i);
+
+            producer.send(message);
+         }
+         
+         System.out.println("Sent messages");
+         
+         //Step 10. Create another consumer on the same queue
+         
+         MessageConsumer consumer2 = session.createConsumer(queue);
+         
+         //Step 11. Consume three messages from consumer2
+         
+         for (int i = 0; i < 3; i++)
+         {         
+            TextMessage message = (TextMessage)consumer2.receive(2000);
+            
+            System.out.println("Consumed message from consumer2: " + message.getText());
+         }
+         
+         //Step 12. Consume five messages from consumer1
+         
+         for (int i = 0; i < 5; i++)
+         {         
+            TextMessage message = (TextMessage)consumer1.receive(2000);
+            
+            System.out.println("Consumed message from consumer1: " + message.getText());
+         }
+         
+         //Step 13. Consume another two messages from consumer2
+         
+         for (int i = 0; i < 2; i++)
+         {         
+            TextMessage message = (TextMessage)consumer2.receive(2000);
+            
+            System.out.println("Consumed message from consumer1: " + message.getText());
+         }
+         
+         return true;
+      }
+      finally
+      {
+         // Step 9. Be sure to close our resources!
+         if (initialContext != null)
+         {
+            initialContext.close();
+         }
+         
+         if (connection != null)
+         {
+            connection.close();
+         }
+      }
+   }
+
+}




More information about the jboss-cvs-commits mailing list