[jboss-svn-commits] JBL Code SVN: r18708 - in labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted: src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Mar 5 15:14:30 EST 2008


Author: beve
Date: 2008-03-05 15:14:30 -0500 (Wed, 05 Mar 2008)
New Revision: 18708

Added:
   labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/RollbackTransactionAction.java
Removed:
   labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/ThrowExceptionAction.java
Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jbm-queue-service.xml
   labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jbmq-queue-service.xml
   labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jboss-esb.xml
   labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/readme.txt
Log:
Work for JBESB-1578 "Update jms_transacted quickstart to demo activation-config properties and transation rollback"


Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jbm-queue-service.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jbm-queue-service.xml	2008-03-05 19:42:00 UTC (rev 18707)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jbm-queue-service.xml	2008-03-05 20:14:30 UTC (rev 18708)
@@ -13,6 +13,9 @@
     xmbean-dd="xmdesc/Queue-xmbean.xml">
 	<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
 	<depends>jboss.messaging:service=PostOffice</depends>
+	<!-- redelivery attempt delay in millis -->
+    <attribute name="RedeliveryDelay">1000</attribute>
+    <attribute name="MaxDeliveryAttempts">15</attribute>
   </mbean>
 
 </server>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jbmq-queue-service.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jbmq-queue-service.xml	2008-03-05 19:42:00 UTC (rev 18707)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jbmq-queue-service.xml	2008-03-05 20:14:30 UTC (rev 18708)
@@ -10,5 +10,8 @@
     name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_jms_transacted_Request_esb">
     <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
 	<depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
+	<!-- redelivery attempt delay in millis -->
+    <attribute name="RedeliveryDelay">1000</attribute>
+    <attribute name="MaxDeliveryAttempts">15</attribute>
   </mbean>
 </server>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jboss-esb.xml	2008-03-05 19:42:00 UTC (rev 18707)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/jboss-esb.xml	2008-03-05 20:14:30 UTC (rev 18708)
@@ -20,6 +20,10 @@
 					  transacted="true"
                   />
               </jms-bus>
+			  <activation-config>
+			  	<!-- The maximum number of times a message is redelivered before it is sent to the DLQ -->
+			  	<property name="dLQMaxResent" value="5"/>
+			   </activation-config>
 
           </jms-jca-provider>
       </providers>
@@ -51,11 +55,11 @@
 					<property name="db-insert-sql" value="insert into jms_transacted_table(data_column) values(?)"/>
 				</action>
                     
-				<!-- 
-					Will throw an Exception upon every other first. This should trigger the transaction to be 
-					rolledback and the message placed back onto the JMS queue.
-				-->
-				<action name="throwExceptionAction" class="org.jboss.soa.esb.samples.quickstart.jmstransacted.test.ThrowExceptionAction"/>
+                <!-- Rollback the current transaction -->
+				<action name="rollbackTransaction" class="org.jboss.soa.esb.samples.quickstart.jmstransacted.test.RollbackTransactionAction">
+					<property name="rollback" value="true"/> <!-- optional as default is true -->
+					<property name="nr-of-rollbacks" value="5"/> <!-- should match dLQMaxResent -->
+				</action>
 				
 				<action name="printMessageDone" class="org.jboss.soa.esb.actions.SystemPrintln">
 					<property name="message" value="JMS Transacted Quickstart processed sucessfully"/>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/readme.txt	2008-03-05 19:42:00 UTC (rev 18707)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/readme.txt	2008-03-05 20:14:30 UTC (rev 18708)
@@ -7,8 +7,7 @@
   This quickstart consists of a single service that contains 4 actions:
   1. Log a statement that we have entered the quickstart.
   2. Insert the contents of the ESB Message object to a database table
-  3. Call a custom action that throws an exception if the message has not
-	 been redelivered. (more on this later)
+  3. Call a custom action that rolls back the current transaction 
   4. Log a statement that we are about to exit the quickstart.
 
   The main thing to look for is that the first time we enter the action processing
@@ -34,7 +33,7 @@
   1. In a command terminal window in this folder ("Window1"), type:
 	 'ant deploy'
 	 This will deploy the quickstart
-  2. Open another command terminal window in this folder ("Window2"), type:
+  2. type:
      'ant runtest'
   3. Switch back to Application Server console to see the output from the ESB
   4. In this folder ("Window1"), type:
@@ -60,52 +59,38 @@
 	 data is committed to the database. In a normal run, when the counter is
 	 '1', the counter should be 2 indicating that only the second commit succeeded.
 	  
-  2. ThrowExceptionAction
-	 Checks if the ESB Messae property 'javax.jms.message.redelivered' 
-	 is false, in which case an IllegalArgumentException will be thrown.
-	 This will will cause the message to be redelivered by JMS transaction handling.
+  2. RollbackTransactionAction
+	 The current transaction is rolled back by the folling code in the process method:
+		TransactionStrategy strategy = TransactionStrategy.getTransactionStrategy(true);
+		log.info( "Setting transaction to rollback only" );
+		strategy.rollbackOnly();
 
   3. jboss-esb.xml
      The message-filter for the jms-bus-filter now specifies 'transacted' attribute.
+	 Notice the "dlQMaxResent" activation-config property:
+		<activation-config>
+			<!-- The maximum number of times a message is redelivered before it is sent to the DLQ -->
+			<property name="dLQMaxResent" value="5"/>
+		</activation-config>
+	 For activation-config properties see : http://www.jboss.org/wiki/Wiki.jsp?page=ConfigJMSMessageListener
+	 Note that if any of the following properites are specified the ESB will throw ConfigurationException:
+		 * 	destination
+		 * 	destinationType
+		 * 	messageSelector
+		 * 	maxMessages
 
-  4. 'ant select'
+  4. jbm-queue-service.xml
+	 Notice the following attributes:
+		<!-- redelivery attempt delay in millis -->
+		<attribute name="RedeliveryDelay">1000</attribute>
+		<attribute name="MaxDeliveryAttempts">15</attribute>
+		MaxDeliveryAttempts must be greater then dLQMaxReset or it will take 
+		priority over dLQMaxReset.
+
+  5. 'ant select'
 	 Ant target that will display all the rows in the database table.
 
-  5. 'ant truncate'
+  6. 'ant truncate'
 	 Ant target that will delete all the rows in the database table.
 	 Useful to clear the table after multiple runs.
 
-
-Inside look:
-============
-  1. Transactions with JMSGateway
-
-	 Lets walk through a client publishing a message to a queue. The queue
-	 will be the queue that our gateway is configured to listen on.
-
-	 1. Client publishes message to JMS queue. It can use a JMS session that
-	 	is transacted to do so or not. It does not matter.
-	 2. The gateway listener will create a JMS session, or use an existing
-		session from the pool, that is transacted. While the JMS Listener
-		is running it will consume a JMS message from the queue, package the 
-		contents of that JMS message into an ESB Message, and use a courier to 
-		pass the message on to the action pipeline.
-
-		Commit:
-	    When the message has be sent to the courier, and no exception has
-		been thrown, the transaction will commit and acknowledge that it
-		has accepted the JMS Message. 
-
-		Rollback:
-		But if an exception has occurred, the transaction will be rolled-back 
-		and the JMS message will not be acknowledged, hence it will be put 
-		back on the queue. 
-
-		Usecase for transactions in JMSGateway
-		Now, this situation may seem far fetched, but one usecase for 
-		it might be that the task of packaging the content of the JMS 
-		Message into the ESB Message is a memory intensive process. 
-		Lets say that one of your machines is under more heavy load then others 
-		which could cause it to throw an OutOfMemory Exception. In this case the 
-		message could be picked up by another ESB instance, which hopefully 
-		can deal with the message.

Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/RollbackTransactionAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/RollbackTransactionAction.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/RollbackTransactionAction.java	2008-03-05 20:14:30 UTC (rev 18708)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.soa.esb.samples.quickstart.jmstransacted.test;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionLifecycle;
+import org.jboss.soa.esb.actions.ActionLifecycleException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.common.TransactionStrategy;
+import org.jboss.soa.esb.common.TransactionStrategyException;
+
+/**
+ * RollbackTransactionAction is a simple action that rolls back the <br>
+ * the current transaction if the rollback field is true.
+ * </p>
+ * Note that this class in only intended to be used with the
+ * jms_transacted quickstart.
+ * </p>
+ * @author <a href="mailto:daniel.bevenius at gmail.com">Daniel Bevenius</a>				
+ *
+ */
+public class RollbackTransactionAction implements ActionLifecycle
+{
+	private Logger log = Logger .getLogger( RollbackTransactionAction.class );
+	
+	/**
+	 * 	Flag indicating if the current transaction should be rolledback
+	 */
+	private boolean rollback;
+	
+	/**
+	 * 	Number of times we should rollback. This is just used so that we 
+	 * 	can specify when  the action should proceed without rollingback the transaction	
+	 */
+	private int nrOfTimesToRollback;
+	
+	/**
+	 * 	Simple counter 
+	 */
+	private static int rollbackCounter;
+	
+	public RollbackTransactionAction( final ConfigTree config ) 
+	{ 
+		rollback = Boolean.parseBoolean( config.getAttribute( "rollback", "true") );
+		nrOfTimesToRollback = Integer.parseInt( config.getAttribute( "nr-of-rollbacks", "3") );
+	}
+	
+	/**
+	 * Will rollback the the current transaction if the rollback 
+	 * configuration paramater is true. Else this is a NOOP and 
+	 * simple passes the message through.
+	 * 
+	 * @param message		- ESB Message object
+	 * @return Message		- ESB Message Object
+	 * @throws TransactionStrategyException		
+	 */
+	public Message process( Message message ) throws TransactionStrategyException
+	{
+		log.debug( "rollback [ " + rollback + "], rollbackCounter [" + rollbackCounter + "], nr-of-rollbacks [" + nrOfTimesToRollback + "]");
+		if ( rollback )
+		{
+			rollbackCounter++;
+			if ( rollbackCounter < nrOfTimesToRollback )
+			{
+    			TransactionStrategy strategy = TransactionStrategy.getTransactionStrategy(true);
+    			log.info( "Setting transaction to rollback only" );
+    			strategy.rollbackOnly();
+    			message = null; 
+			}
+			else
+			{
+				rollbackCounter = 0;
+			}
+		}
+		return message;
+	}
+	
+	public void processException(final Message message, final Throwable th)   {  }
+	public void destroy() throws ActionLifecycleException {}
+	public void initialise() throws ActionLifecycleException {}
+	
+}

Deleted: labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/ThrowExceptionAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/ThrowExceptionAction.java	2008-03-05 19:42:00 UTC (rev 18707)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/ThrowExceptionAction.java	2008-03-05 20:14:30 UTC (rev 18708)
@@ -1,71 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated 
- * by the @authors tag. All rights reserved. 
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
- * MA  02110-1301, USA.
- * 
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-package org.jboss.soa.esb.samples.quickstart.jmstransacted.test;
-
-import static org.jboss.soa.esb.notification.jms.JMSPropertiesSetter.JMS_REDELIVERED;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.actions.ActionLifecycle;
-import org.jboss.soa.esb.actions.ActionLifecycleException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Message;
-
-/**
- * ThrowExceptionAction is a simple action that throws an exception <br>
- * if the message has not been redelivered (first call to this action). 
- * </p>
- * Note that this class in only intended to be used with the
- * jms_transacted quickstart.
- * </p>
- * @author <a href="mailto:daniel.bevenius at gmail.com">Daniel Bevenius</a>				
- *
- */
-public class ThrowExceptionAction implements ActionLifecycle
-{
-	private Logger log = Logger .getLogger( ThrowExceptionAction.class );
-	
-	public ThrowExceptionAction( final ConfigTree config ) { }
-	
-	/**
-	 * Checks if the ESB Messae property 'javax.jms.message.redelivered' 
-	 * is false, in which case an IllegalArgumentException will be thrown. <br>
-	 * This will will cause the message to be redelivered by JMS transaction 
-	 * handling.
-	 * 
-	 * @param message		- ESB Message object
-	 * @return Message		- unchanged ESB Message Object
-	 */
-	public Message process( final Message message )
-	{
-		final Boolean redelivered = (Boolean) message.getProperties().getProperty( JMS_REDELIVERED );
-		log.info("[" +JMS_REDELIVERED + ":" + redelivered + "]" );
-		
-		if ( redelivered )
-			return message;
-		else
-			throw new IllegalStateException( "[Throwing Exception to trigger a transaction rollback]");
-	}
-	
-	public void processException(final Message message, final Throwable th)   {  }
-	public void destroy() throws ActionLifecycleException {}
-	public void initialise() throws ActionLifecycleException {}
-	
-}




More information about the jboss-svn-commits mailing list