[jboss-cvs] JBoss Messaging SVN: r6223 - in trunk/examples/jms: common and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 31 00:54:40 EDT 2009


Author: gaohoward
Date: 2009-03-31 00:54:40 -0400 (Tue, 31 Mar 2009)
New Revision: 6223

Added:
   trunk/examples/jms/transactional/
   trunk/examples/jms/transactional/READ_ME.txt
   trunk/examples/jms/transactional/build.xml
   trunk/examples/jms/transactional/src/
   trunk/examples/jms/transactional/src/org/
   trunk/examples/jms/transactional/src/org/jboss/
   trunk/examples/jms/transactional/src/org/jboss/jms/
   trunk/examples/jms/transactional/src/org/jboss/jms/example/
   trunk/examples/jms/transactional/src/org/jboss/jms/example/TransactionalExample.java
Modified:
   trunk/examples/jms/common/build.xml
Log:
added transactional jms example, and added a clean Ant target.


Modified: trunk/examples/jms/common/build.xml
===================================================================
--- trunk/examples/jms/common/build.xml	2009-03-30 21:34:40 UTC (rev 6222)
+++ trunk/examples/jms/common/build.xml	2009-03-31 04:54:40 UTC (rev 6223)
@@ -136,4 +136,8 @@
          <classpath refid="jms.runtime.classpath"/>
       </java>
    </target>
-</project>
\ No newline at end of file
+
+   <target name="clean">
+   	  <delete dir="./build" quiet="true" />
+   </target>
+</project>

Added: trunk/examples/jms/transactional/READ_ME.txt
===================================================================

Added: trunk/examples/jms/transactional/build.xml
===================================================================
--- trunk/examples/jms/transactional/build.xml	                        (rev 0)
+++ trunk/examples/jms/transactional/build.xml	2009-03-31 04:54:40 UTC (rev 6223)
@@ -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 Transactional Example">
+
+   <import file="../common/build.xml"/>
+
+   <target name="run">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.TransactionalExample"/>
+      </antcall>
+   </target>
+
+   <target name="runRemote">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.TransactionalExample"/>
+         <param name="jbm.example.runServer" value="false"/>
+      </antcall>
+   </target>
+
+</project>
\ No newline at end of file

Added: trunk/examples/jms/transactional/src/org/jboss/jms/example/TransactionalExample.java
===================================================================
--- trunk/examples/jms/transactional/src/org/jboss/jms/example/TransactionalExample.java	                        (rev 0)
+++ trunk/examples/jms/transactional/src/org/jboss/jms/example/TransactionalExample.java	2009-03-31 04:54:40 UTC (rev 6223)
@@ -0,0 +1,98 @@
+/*
+   * 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.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * A simple JMS example that sends and consume message transactionally.
+ *
+ * @author <a href="hgao at redhat.com">Howard Gao</a>
+ */
+public class TransactionalExample extends JMSExample
+{
+   public static void main(String[] args)
+   {
+      new TransactionalExample().run(args);
+   }
+
+   public void runExample()
+   {
+      Connection connection = null;
+      try
+      {
+         //create an initial context, env will be picked up from client-jndi.properties
+         InitialContext initialContext = getContext();
+         Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
+         ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+         
+         connection = cf.createConnection();
+         Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+         
+         MessageProducer producer = session.createProducer(queue);
+         Message message = session.createTextMessage("This is a text message!");
+         
+         log.info("sending message to queue");
+         producer.send(message);
+         
+         session.commit();
+         
+         MessageConsumer messageConsumer = session.createConsumer(queue);
+         connection.start();
+         TextMessage message2 = (TextMessage) messageConsumer.receive(5000);
+         
+         session.commit();
+
+         log.info("message received from queue");
+         log.info("message = " + message2.getText());
+
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+      finally
+      {
+         if(connection != null)
+         {
+            try
+            {
+               connection.close();
+            }
+            catch (JMSException e)
+            {
+               e.printStackTrace();
+            }
+         }
+      }
+   }
+
+}




More information about the jboss-cvs-commits mailing list