[jboss-cvs] JBoss Messaging SVN: r5154 - in branches/Branch_JBMESSAGING_1416/docs/examples: ordering-group and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 20 01:53:18 EDT 2008


Author: gaohoward
Date: 2008-10-20 01:53:18 -0400 (Mon, 20 Oct 2008)
New Revision: 5154

Added:
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/README.html
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/build.xml
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/jndi.properties
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/log4j.xml
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/jboss/
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/jboss/example/
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/jboss/example/jms/
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/
   branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java
Log:
JBMESSAGING-1416


Added: branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/README.html
===================================================================
--- branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/README.html	                        (rev 0)
+++ branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/README.html	2008-10-20 05:53:18 UTC (rev 5154)
@@ -0,0 +1,132 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <meta content="text/html; charset=ISO-8859-1"
+ http-equiv="content-type">
+  <title>JBoss Messaging Example - JMS Queue</title>
+</head>
+<body>
+<br>
+<h1>JBoss Messaging Queue Example</h1>
+$Revision: 2750 $
+<h2>Overview</h2>
+<br>
+This example creates a JMS Connection to a JBoss Messaging instance
+and uses it to create a session and a message producer, which sends a
+message to the queue "queue/testQueue".&nbsp; Then, the example uses
+the same connection to create a consumer that that reads
+a single message from the queue. The example is considered successful
+if the message consumer receives without any error the message that was
+sent by the producer. <br>
+<br>
+This example relies on having access to a running JBoss Messaging
+instance.
+The JBoss Messaging instance must be installed and started according to
+the
+"Installation" paragraph from the release documentation. However, the
+example will automatically deploy its own queue, unless a queue with
+the same name is already deployed. <br>
+<br>
+This example also relies on having access to <span
+ style="font-family: monospace;">jboss-messaging-client.jar</span>
+archive that comes with the release bundle. If you run this example
+from an unzipped installation bundle, the example run script is
+correctly configured to find the client jar. Otherwise, you must modify
+example's <span style="font-family: monospace;">build.xml</span>
+accordingly.<br>
+<br>
+<span style="font-style: italic;"></span>
+<h2>Running the example</h2>
+1. Set up the JBOSS_HOME environment variable to point to the JBoss
+instance you deployed JBoss Messaging into. For example, if you
+deployed JBoss Messaging in <span style="font-family: monospace;">C:\jboss-4.2.0.GA\server\messaging\deploy,</span>
+then your JBOSS_HOME value should be <span
+ style="font-family: monospace;">C:\</span><span
+ style="font-family: monospace;">jboss-4.2.0.GA</span><br>
+<span style="font-family: monospace;"></span><span
+ style="font-family: monospace;"></span><br>
+2. Go to the example's home directory<br>
+<br>
+<div style="margin-left: 40px;"><span style="font-family: monospace;">cd
+...\examples\queue</span><br>
+</div>
+<br>
+3. Run the example:<br>
+<br>
+<div style="margin-left: 40px;"><span style="font-family: monospace;">ant</span>
+<br>
+<br>
+<br>
+</div>
+The output of a successful run should be similar to:<br>
+<div style="margin-left: 40px;"><br>
+</div>
+<table
+ style="width: 90%; text-align: left; font-family: monospace; background-color: rgb(204, 204, 204); margin-left: 40px;"
+ border="1" cellpadding="2" cellspacing="2">
+  <tbody>
+    <tr>
+      <td style="vertical-align: top;">
+<pre>
+Buildfile: build.xml
+
+identify:
+     [echo] ###########################################################################
+     [echo] #                       Running the QUEUE example                         #
+     [echo] ###########################################################################
+     [echo] The queue:      testQueue
+     [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar
+
+sanity-check:
+
+init:
+    [mkdir] Created dir: C:\java\messaging\docs\examples\queue\output\classes
+    [mkdir] Created dir: C:\java\messaging\docs\examples\common\output\classes
+
+compile:
+    [javac] Compiling 5 source files to C:\java\messaging\docs\examples\common\output\classes
+    [javac] Compiling 1 source file to C:\java\messaging\docs\examples\queue\output\classes
+
+run:
+     [java] Queue /queue/testQueue exists
+     [java] The message was successfully sent to the testQueue queue
+     [java] Received message: Hello!
+     [java] The example connected to JBoss Messaging version 1.3.0.GA (1.3)
+     [java] 
+     [java] #####################
+     [java] ###    SUCCESS!   ###
+     [java] #####################
+
+BUILD SUCCESSFUL
+Total time: 4 seconds
+</pre>
+      </td>
+    </tr>
+  </tbody>
+</table>
+<div style="margin-left: 40px;"><br>
+</div>
+<br>
+<br>
+<h2>Troublesooting</h2>
+<h3>1. I get <span style="font-family: monospace;">"javax.jms.JMSSecurityException:
+User null is NOT authenticated" <br>
+</span></h3>
+You probably didn't install JBoss Messaging correctly. A fresh JBoss
+Messaging installation requires changes in the security configuration
+of a <span style="font-family: monospace;">default </span>JBoss
+instance, specifically a properly configured "<small><span
+ style="font-family: courier new,courier,monospace;">messaging</span></small>"
+security domain.&nbsp; Follow the instructions from the "Installation"
+paragraph of the release documentation. <br>
+<br>
+<br>
+<hr style="width: 100%; height: 2px;"><br>
+<br>
+<br>
+<br>
+<br>
+<br>
+<br>
+</body>
+</html>

Added: branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/build.xml
===================================================================
--- branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/build.xml	                        (rev 0)
+++ branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/build.xml	2008-10-20 05:53:18 UTC (rev 5154)
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+   To run the example, set JBOSS_HOME and run ant (with no parameters)
+
+   $Id: build.xml 3140 2007-09-26 08:44:19Z ataylor $
+
+ -->
+
+<project name="OrderingGroupExample" default="run">
+
+   <property environment="ENV"/>
+
+   <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
+   <property file="../examples.properties"/>
+   <property name="messaging.client.jar.path" value="../../"/>
+   <property name="messaging.client.jar.name" value="jboss-messaging-client.jar"/>
+   <property name="jboss.home" value="${ENV.JBOSS_HOME}"/>
+   <property name="jboss.configuration" value="messaging"/>
+   <property name="example.queue.name" value="testQueue"/>
+
+   <path id="common.compilation.classpath">
+      <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </path>
+
+   <path id="example.compilation.classpath">
+      <path refid="common.compilation.classpath"/>
+      <pathelement path="../common/output/classes"/>
+   </path>
+
+   <path id="execution.classpath">
+      <pathelement path="./etc"/>
+      <pathelement path="../common/output/classes"/>
+      <pathelement path="./output/classes"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/jboss-remoting.jar"/>
+      <fileset file="${jboss.home}/client/jbossall-client.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/log4j.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/javassist.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/jboss-aop-jdk50.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/trove.jar"/>
+   </path>
+
+   <target name="identify">
+      <echo message="###########################################################################"/>
+      <echo message="#                  Running the OrderingGroup example                      #"/>
+      <echo message="###########################################################################"/>
+      <echo message="The queue:      ${example.queue.name}"/>
+      <echo message="The client jar: ${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </target>
+
+   <target name="sanity-check" depends="identify">
+      <available property="client.jar.present" file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fail message="Could not find client jar ${messaging.client.jar.path}/${messaging.client.jar.name}"
+            unless="client.jar.present"/>
+   </target>
+
+   <target name="init" depends="sanity-check">
+      <mkdir dir="./output/classes"/>
+      <mkdir dir="../common/output/classes"/>
+   </target>
+
+   <target name="compile" depends="init">
+      <javac destdir="../common/output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="../common/src"/>
+         <classpath refid="common.compilation.classpath"/>
+      </javac>
+      <javac destdir="./output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="./src"/>
+         <classpath refid="example.compilation.classpath"/>
+      </javac>
+   </target>
+
+   <target name="run" depends="compile">
+      <!-- QueueExample expects to find the name of the queue to connect to as value of the
+           'example.queue.name' property, which *may* be defined by calling ants when this example
+            is used in a smoke test -->
+      <java classname="org.jboss.example.jms.ordering.OrderingGroupExample"
+            classpathref="execution.classpath" fork="yes" failonerror="true">
+         <sysproperty key="example.queue.name" value="${example.queue.name}"/>
+         <sysproperty key="com.sun.management.jmxremote" value=""/>
+         <!--
+         <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=example"/>
+         -->
+      </java>
+   </target>
+
+   <target name="clean">
+      <delete dir="./output" quiet="true"/>
+      <delete dir="../common/output" quiet="true"/>
+   </target>
+
+</project>
+

Added: branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/jndi.properties
===================================================================
--- branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/jndi.properties	                        (rev 0)
+++ branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/jndi.properties	2008-10-20 05:53:18 UTC (rev 5154)
@@ -0,0 +1,4 @@
+### JBossNS properties
+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: branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/log4j.xml
===================================================================
--- branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/log4j.xml	                        (rev 0)
+++ branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/etc/log4j.xml	2008-10-20 05:53:18 UTC (rev 5154)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 2318 2007-02-15 02:11:43Z ovidiu.feodorov at jboss.com $ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <param name="Target" value="System.out"/>
+      <param name="Threshold" value="INFO"/>
+      <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p @%t [%c{1}] %m%n"/>
+      </layout>
+   </appender>
+
+  <root>
+      <appender-ref ref="CONSOLE"/>
+   </root>
+
+</log4j:configuration>

Added: branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java
===================================================================
--- branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java	                        (rev 0)
+++ branches/Branch_JBMESSAGING_1416/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java	2008-10-20 05:53:18 UTC (rev 5154)
@@ -0,0 +1,176 @@
+/*
+ * 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.
+ */
+package org.jboss.example.jms.ordering;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Message;
+import javax.naming.InitialContext;
+
+import org.jboss.example.jms.common.ExampleSupport;
+import org.jboss.jms.client.JBossMessageProducer;
+
+/**
+ * This example creates a JMS Connection to a JBoss Messaging instance and uses it to create a
+ * session and a message producer, which sends a message to the queue "queue/testQueue".  Then, the
+ * example uses the same connection to create a consumer that that reads a single message from the
+ * queue. The example is considered successful if the message consumer receives without any error
+ * the message that was sent by the producer.
+ * 
+ * Since this example is also used by the smoke test, it is essential that the VM exits with exit
+ * code 0 in case of successful execution and a non-zero value on failure.
+ *
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:luc.texier at jboss.org">Luc Texier</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 2868 $</tt>
+ *
+ * $Id: QueueExample.java 2868 2007-07-10 20:22:16Z timfox $
+ */
+public class OrderingGroupExample extends ExampleSupport
+{
+   
+   public void example() throws Exception
+   {
+      String destinationName = getDestinationJNDIName();
+      
+      InitialContext ic = null;
+      ConnectionFactory cf = null;
+      Connection connection =  null;
+
+      try
+      {         
+         ic = new InitialContext();
+         
+         cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+         Queue queue = (Queue)ic.lookup(destinationName);
+         log("Queue " + destinationName + " exists");
+         
+         connection = cf.createConnection();
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        
+         JBossMessageProducer producer1 = (JBossMessageProducer)session.createProducer(queue);
+         TextMessage normalMsg = session.createTextMessage("Hello-normal");
+         TextMessage normalMsg1 = session.createTextMessage("Hello-normal-1");
+
+         log("Sending mormal message with lower priority 1");
+         producer1.send(normalMsg1, Message.DEFAULT_DELIVERY_MODE, 1, Message.DEFAULT_TIME_TO_LIVE);
+
+         JBossMessageProducer producer = (JBossMessageProducer)session.createProducer(queue);
+         producer.enableOrderingGroup("MyOrderingGroup");
+         
+         TextMessage message = session.createTextMessage("Hello!");
+         message.setJMSPriority(0);
+         log("Sending message with priority 0");
+         producer.send(message, Message.DEFAULT_DELIVERY_MODE, 0, Message.DEFAULT_TIME_TO_LIVE);
+         
+         TextMessage message2 = session.createTextMessage("Hello-1!");
+         log("Sending message2 with priority 8");
+         producer.send(message2, Message.DEFAULT_DELIVERY_MODE, 8, Message.DEFAULT_TIME_TO_LIVE);
+
+         log("Sending normal message with priority 9");
+         producer1.send(normalMsg, Message.DEFAULT_DELIVERY_MODE, 9, Message.DEFAULT_TIME_TO_LIVE);
+         
+         TextMessage message3 = session.createTextMessage("Hello-2!");
+         log("Sending message3 with priority 5");
+         producer.send(message3, Message.DEFAULT_DELIVERY_MODE, 5, Message.DEFAULT_TIME_TO_LIVE);
+         
+         log("The message was successfully sent to the " + queue.getQueueName() + " queue");
+         
+         MessageConsumer consumer =  session.createConsumer(queue);
+         
+         connection.start();
+         
+         message = (TextMessage)consumer.receive();
+
+         //while (message != null)
+         //{
+             log("Received message: " + message.getText());
+
+             message = (TextMessage)consumer.receive();
+             log("Received message2: " + message.getText());
+         //}
+         
+             message = (TextMessage)consumer.receive();
+             log("Received message3: " + message.getText());
+         
+             message = (TextMessage)consumer.receive();
+             log("Received message4: " + message.getText());
+         
+             message = (TextMessage)consumer.receive();
+             log("Received message5: " + message.getText());
+         
+         displayProviderInfo(connection.getMetaData());
+                 
+      }
+      finally
+      {         
+         if(ic != null)
+         {
+            try
+            {
+               ic.close();
+            }
+            catch(Exception e)
+            {
+               throw e;
+            }
+         }
+         
+         // ALWAYS close your connection in a finally block to avoid leaks.
+         // Closing connection also takes care of closing its related objects e.g. sessions.
+         closeConnection(connection);
+      }
+   }
+   
+   private void closeConnection(Connection con)
+   {      
+      try
+      {
+         if (con != null)
+         {
+            con.close();
+         }         
+      }
+      catch(JMSException jmse)
+      {
+         log("Could not close connection " + con +" exception was " + jmse);
+      }
+   }
+      
+   protected boolean isQueueExample()
+   {
+      return true;
+   }
+   
+   public static void main(String[] args)
+   {
+      new OrderingGroupExample().run();
+   }
+      
+}




More information about the jboss-cvs-commits mailing list