[jboss-cvs] JBoss Messaging SVN: r1404 - in trunk/docs/examples: . topic-cluster topic-cluster/etc topic-cluster/src topic-cluster/src/org topic-cluster/src/org/jboss topic-cluster/src/org/jboss/example topic-cluster/src/org/jboss/example/jms topic-cluster/src/org/jboss/example/jms/topiccluster

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 29 20:32:10 EDT 2006


Author: clebert.suconic at jboss.com
Date: 2006-09-29 20:32:08 -0400 (Fri, 29 Sep 2006)
New Revision: 1404

Added:
   trunk/docs/examples/topic-cluster/
   trunk/docs/examples/topic-cluster/README.html
   trunk/docs/examples/topic-cluster/build.xml
   trunk/docs/examples/topic-cluster/do-not-distribute.properties
   trunk/docs/examples/topic-cluster/etc/
   trunk/docs/examples/topic-cluster/etc/jndi.properties
   trunk/docs/examples/topic-cluster/etc/log4j.xml
   trunk/docs/examples/topic-cluster/src/
   trunk/docs/examples/topic-cluster/src/org/
   trunk/docs/examples/topic-cluster/src/org/jboss/
   trunk/docs/examples/topic-cluster/src/org/jboss/example/
   trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/
   trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/
   trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/ExampleListener.java
   trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/TopicConsumer.java
   trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/TopicExample.java
Log:
Adding proposed clustered example

Added: trunk/docs/examples/topic-cluster/README.html
===================================================================
--- trunk/docs/examples/topic-cluster/README.html	2006-09-29 21:07:09 UTC (rev 1403)
+++ trunk/docs/examples/topic-cluster/README.html	2006-09-30 00:32:08 UTC (rev 1404)
@@ -0,0 +1,143 @@
+<!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 Topic</title>
+</head>
+<body>
+<br>
+<h1>JBoss Messaging Topic Example</h1>
+$Revision: 1017 $
+<h2>Overview</h2>
+<br>
+This example creates a JMS Connection to a JBoss Messaging instance
+and uses it to create a session, a publisher and a subscriber. The
+publisher sends a message to the topic. The example is considered
+successful
+if the topic subscriber receives the message.<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.&nbsp; However,
+the example will automatically deploy its own topic, unless a topic
+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>
+<span style="font-style: italic;"></span><br>
+<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.0.3SP1\server\default\deploy,</span>
+then your JBOSS_HOME value should be <span
+ style="font-family: monospace;">C:\</span><span
+ style="font-family: monospace;">jboss-4.0.3SP1.</span><br>
+<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\topic</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;">
+      <div style="margin-left: 40px;"><br>
+      </div>
+$ ant<br>
+Buildfile: build.xml<br>
+      <br>
+identify:<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo]
+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo]
+X&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+Running the TOPIC
+example&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+X<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo]
+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo] The topic: testTopic<br>
+      <br>
+sanity-check:<br>
+      <br>
+init:<br>
+&nbsp;&nbsp;&nbsp; [mkdir] Created dir:
+C:\work\src\cvs\jboss-head\jms\docs\examples\topic\output<br>
+&nbsp;&nbsp;&nbsp; [mkdir] Created dir:
+C:\work\src\cvs\jboss-head\jms\docs\examples\common\output<br>
+      <br>
+compile:<br>
+&nbsp;&nbsp;&nbsp; [javac] Compiling 2 source files to
+C:\work\src\cvs\jboss-head\jms\docs\examples\common\output<br>
+&nbsp;&nbsp;&nbsp; [javac] Compiling 2 source files to
+C:\work\src\cvs\jboss-head\jms\docs\examples\topic\output<br>
+      <br>
+run:<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] Topic /topic/testTopic exists<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] The message was successfully published
+on the topic<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] Received message: Hello!<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] The example connected to JBoss
+Messaging version 1.0.1.CR3 (1.0)<br>
+      <br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] #####################<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] ###&nbsp;&nbsp;&nbsp;
+SUCCESS!&nbsp;&nbsp; ###<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] #####################<br>
+      <br>
+BUILD SUCCESSFUL<br>
+Total time: 4 seconds<br>
+      <br>
+      <br>
+      </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: trunk/docs/examples/topic-cluster/build.xml
===================================================================
--- trunk/docs/examples/topic-cluster/build.xml	2006-09-29 21:07:09 UTC (rev 1403)
+++ trunk/docs/examples/topic-cluster/build.xml	2006-09-30 00:32:08 UTC (rev 1404)
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+   To run the example, set JBOSS_HOME and run ant (with no parameters)
+
+   $Id: build.xml 974 2006-05-22 21:35:38 -0600 (Mon, 22 May 2006) ovidiu $
+
+ -->
+
+<project name="TopicExample" default="run" >
+
+   <property environment="ENV"/>
+
+   <!--
+        If you don't find this file in the current directory, it's ok, it's intended to provide
+        defaults for in-workarea testing and it's not meant for distribution with the example bundle.
+   -->
+   <property file="do-not-distribute.properties"/>
+
+   <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
+   <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="example.topic.name" value="testTopic"/>
+
+   <path id="common.compilation.classpath">
+      <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
+      <fileset file="${jboss.home}/client/jboss-j2se.jar"/>
+   </path>
+
+   <path id="example.compilation.classpath">
+      <path refid="common.compilation.classpath"/>
+      <pathelement path="../common/output"/>
+   </path>
+
+   <path id="execution.classpath">
+      <pathelement path="./etc"/>
+      <pathelement path="../common/output"/>
+      <pathelement path="./output"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </path>
+
+   <target name="identify">
+      <echo message="###########################################################################"/>
+      <echo message="#                       Running the TOPIC example                         #"/>
+      <echo message="###########################################################################"/>
+      <echo message="The topic:      ${example.topic.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"/>
+      <mkdir dir="../common/output"/>
+   </target>
+
+   <target name="compile" depends="init">
+      <javac destdir="../common/output" debug="on" debuglevel="lines,vars,source">
+         <src path="../common/src"/>
+         <classpath refid="common.compilation.classpath"/>
+      </javac>
+      <javac destdir="./output" debug="on" debuglevel="lines,vars,source">
+         <src path="./src"/>
+         <classpath refid="example.compilation.classpath"/>
+      </javac>
+   </target>
+
+   <target name="run" depends="compile">
+      <!-- TopicExample expects to find the name of the topic to connect to as value of the
+           'example.topic.name' property, which *may* be defined by calling ants when this example
+            is used in a smoke test -->
+      <java classname="org.jboss.example.jms.topiccluster.TopicExample"
+         classpathref="execution.classpath" fork="yes" failonerror="true">
+         <sysproperty key="example.topic.name" value="${example.topic.name}"/>
+         <sysproperty key="CLUSTER_IP_1" value="${CLUSTER_IP_1}"/>
+         <sysproperty key="CLUSTER_IP_2" value="${CLUSTER_IP_2}"/>
+         <!--
+         <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: trunk/docs/examples/topic-cluster/do-not-distribute.properties
===================================================================
--- trunk/docs/examples/topic-cluster/do-not-distribute.properties	2006-09-29 21:07:09 UTC (rev 1403)
+++ trunk/docs/examples/topic-cluster/do-not-distribute.properties	2006-09-30 00:32:08 UTC (rev 1404)
@@ -0,0 +1,10 @@
+#
+# This file provides values for in-workarea example testing.
+# DO NOT DISTRIBUTE!
+#
+messaging.client.jar.path=../../../output/lib
+messaging.client.jar.name=jboss-messaging-client.jar
+jboss.configuration=messaging
+CLUSTER_IP_1=10.1.5.1
+CLUSTER_IP_2=10.1.5.2
+jboss.home=/home/clebert/workspaces/jboss-4.0-tmp/build/output/jboss-4.0.5.GA

Added: trunk/docs/examples/topic-cluster/etc/jndi.properties
===================================================================
--- trunk/docs/examples/topic-cluster/etc/jndi.properties	2006-09-29 21:07:09 UTC (rev 1403)
+++ trunk/docs/examples/topic-cluster/etc/jndi.properties	2006-09-30 00:32:08 UTC (rev 1404)
@@ -0,0 +1,4 @@
+### JBossNS properties
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://10.1.5.1:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/docs/examples/topic-cluster/etc/log4j.xml
===================================================================
--- trunk/docs/examples/topic-cluster/etc/log4j.xml	2006-09-29 21:07:09 UTC (rev 1403)
+++ trunk/docs/examples/topic-cluster/etc/log4j.xml	2006-09-30 00:32:08 UTC (rev 1404)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 536 2005-12-22 00:28:39 -0600 (Thu, 22 Dec 2005) ovidiu $ -->
+
+<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: trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/ExampleListener.java
===================================================================
--- trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/ExampleListener.java	2006-09-29 21:07:09 UTC (rev 1403)
+++ trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/ExampleListener.java	2006-09-30 00:32:08 UTC (rev 1404)
@@ -0,0 +1,61 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.topiccluster;
+
+import javax.jms.MessageListener;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision: 536 $</tt>
+
+ * $Id: ExampleListener.java 536 2005-12-22 00:28:39 -0600 (Thu, 22 Dec 2005) ovidiu $
+ */
+public class ExampleListener implements MessageListener
+{
+
+   public ExampleListener(String serverIP)
+   {
+       this.serverIP = serverIP;
+   }
+
+   String serverIP;
+   ArrayList messages = new ArrayList();
+
+   public synchronized void onMessage(Message message)
+   {
+      System.out.println("receiving message on server " + serverIP);
+      this.messages.add(message);
+      notifyAll();
+   }
+
+   public synchronized Message[] getMessages()
+   {
+      return (Message[])messages.toArray(new TextMessage[messages.size()]);
+   }
+
+
+   protected synchronized void waitForMessage(int numberOfExpectedMessages)
+   {
+      if (messages.size()==numberOfExpectedMessages)
+      {
+         return;
+      }
+
+      try
+      {
+         wait(5000);
+      }
+      catch(InterruptedException e)
+      {
+         // OK
+      }
+   }
+}

Added: trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/TopicConsumer.java
===================================================================
--- trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/TopicConsumer.java	2006-09-29 21:07:09 UTC (rev 1403)
+++ trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/TopicConsumer.java	2006-09-30 00:32:08 UTC (rev 1404)
@@ -0,0 +1,79 @@
+/*
+* 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.topiccluster;
+
+import javax.naming.InitialContext;
+import javax.jms.*;
+
+
+/**
+ * @author Clebert Suconic
+ */
+public class TopicConsumer extends Thread
+{
+
+    InitialContext ic;
+    String destinationName;
+    String serverName;
+    public int numberOfMessagesReceived=0;
+    public TopicConsumer(InitialContext ctx, String destinationName, String serverName)
+    {
+        this.ic=ctx;
+        this.destinationName=destinationName;
+        this.serverName=serverName;
+    }
+    public void run()
+    {
+        try
+        {
+            ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+
+            Topic topic = (Topic)ic.lookup(destinationName);
+
+            Connection connection = cf.createConnection();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            MessageConsumer subscriber = session.createConsumer(topic);
+
+            ExampleListener messageListener = new ExampleListener(serverName);
+            subscriber.setMessageListener(messageListener);
+            connection.start();
+
+
+            messageListener.waitForMessage(1);
+
+             TextMessage messages[] = (TextMessage[])messageListener.getMessages();
+             for (int i=0;i<messages.length;i++)
+             {
+                 TextMessage message = messages[i];
+                 System.out.println("Message received on " + serverName + " result=" + message.getText());
+                 numberOfMessagesReceived++;
+             }
+
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+
+    }
+}

Added: trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/TopicExample.java
===================================================================
--- trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/TopicExample.java	2006-09-29 21:07:09 UTC (rev 1403)
+++ trunk/docs/examples/topic-cluster/src/org/jboss/example/jms/topiccluster/TopicExample.java	2006-09-30 00:32:08 UTC (rev 1404)
@@ -0,0 +1,131 @@
+/*
+* 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.topiccluster;
+
+import org.jboss.example.jms.common.ExampleSupport;
+import org.jboss.example.jms.common.ExampleSupportCluster;
+
+import javax.naming.InitialContext;
+import javax.jms.*;
+
+/**
+ * The example creates a connection to the default provider and uses the connection to send a
+ * message to the topic "queue/testTopic". The message must be received by a topic subscriber.
+ *
+ * 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 jboss.org">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: 1001 $</tt>
+ *
+ * $Id: TopicExample.java 1001 2006-06-24 03:05:40 -0600 (Sat, 24 Jun 2006) timfox $
+ */
+public class TopicExample extends ExampleSupportCluster
+{
+   public void example() throws Exception
+   {
+      String destinationName = getDestinationJNDIName();
+
+       InitialContext ic = null;
+       InitialContext ic2 = null;
+       Connection connection = null;
+
+       try {
+
+           ic = getServerContext(1);
+           ic2 = getServerContext(2);
+
+           TopicConsumer consumer1 = startConsumer(ic, destinationName,"consumer 1");
+           TopicConsumer consumer2 = startConsumer(ic2, destinationName,"consumer 2");
+
+           ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+
+           Topic topic = (Topic)ic.lookup(destinationName);
+           log("Topic " + destinationName + " exists");
+
+           connection = cf.createConnection();
+           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+           MessageProducer publisher = session.createProducer(topic);
+
+
+
+
+
+           TextMessage message = session.createTextMessage("Hello!");
+           publisher.send(message);
+           log("The message was successfully published on the topic");
+
+           Thread.sleep(2000);
+           displayProviderInfo(connection.getMetaData());
+
+           assertEquals(1,consumer1.numberOfMessagesReceived);
+           assertEquals(1,consumer2.numberOfMessagesReceived);
+
+       }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 TopicConsumer startConsumer(InitialContext ic, String destinationName, String serverName) {
+        TopicConsumer consumer = new TopicConsumer(ic,destinationName,serverName);
+        consumer.start();
+        return consumer;
+    }
+
+    private void closeConnection(Connection con) throws JMSException {
+
+        try {
+            if (con != null) {
+                con.close();
+            }
+
+        }catch(JMSException jmse) {
+            log("Could not close connection " + con +" exception was " +jmse);
+            throw jmse;
+        }
+    }
+
+
+   protected boolean isQueueExample()
+   {
+      return false;
+   }
+
+   public static void main(String[] args)
+   {
+      new TopicExample().run();
+   }
+
+}




More information about the jboss-cvs-commits mailing list