[jboss-svn-commits] JBL Code SVN: r20021 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/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
Mon May 19 07:44:30 EDT 2008
Author: beve
Date: 2008-05-19 07:44:30 -0400 (Mon, 19 May 2008)
New Revision: 20021
Added:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/RollbackTransactionAction.java
Removed:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/ThrowExceptionAction.java
Modified:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/build.xml
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/jboss-esb.xml
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/readme.txt
Log:
Work for JBESB-1664 "Add an expected output portion to jms_transacted QS"
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/build.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/build.xml 2008-05-19 11:36:35 UTC (rev 20020)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/build.xml 2008-05-19 11:44:30 UTC (rev 20021)
@@ -27,9 +27,12 @@
<arg value="Hello Transacted JMS World]"/>
<classpath refid="exec-classpath"/>
</java>
+ <sleep milliseconds="4000"/>
+ <antcall target="select"/>
+ <antcall target="truncate"/>
</target>
- <target name="select" depends="dependencies" description="select * from jsm_transacted_table">
+ <target name="select">
<property name="hsqldb.jar"
value="${org.jboss.esb.server.home}/server/${org.jboss.esb.server.config}/lib/hsqldb.jar"/>
<echo>Select * from jms_transacted_table</echo>
@@ -50,10 +53,10 @@
</target>
- <target name="truncate" depends="dependencies" description="delete from jms_transacted_table">
+ <target name="truncate">
<property name="hsqldb.jar"
value="${org.jboss.esb.server.home}/server/${org.jboss.esb.server.config}/lib/hsqldb.jar"/>
- <echo>Delete from jms_transacted_table </echo>
+ <echo>(clean up) Delete from jms_transacted_table </echo>
<sql
print="true"
driver="org.hsqldb.jdbcDriver"
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/jboss-esb.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/jboss-esb.xml 2008-05-19 11:36:35 UTC (rev 20020)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/jboss-esb.xml 2008-05-19 11:44:30 UTC (rev 20021)
@@ -39,7 +39,7 @@
<actions mep="OneWay">
<action name="printMessage" class="org.jboss.soa.esb.actions.SystemPrintln">
- <property name="message" value="JMS Transacted Quickstart start..."/>
+ <property name="message" value="JMS Transacted Quickstart enter. Message body"/>
<property name="printfull" value="false"/>
</action>
@@ -48,14 +48,10 @@
<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"/>
+ <action name="rollbackTransaction" class="org.jboss.soa.esb.samples.quickstart.jmstransacted.test.RollbackTransactionAction"/>
<action name="printMessageDone" class="org.jboss.soa.esb.actions.SystemPrintln">
- <property name="message" value="JMS Transacted Quickstart processed sucessfully"/>
+ <property name="message" value="JMS Transacted Quickstart processed sucessfully. Message body"/>
<property name="printfull" value="false"/>
</action>
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/readme.txt
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/readme.txt 2008-05-19 11:36:35 UTC (rev 20020)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/readme.txt 2008-05-19 11:44:30 UTC (rev 20021)
@@ -6,9 +6,8 @@
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)
+ 2. Insert the contents of the ESB Message object to a database table.
+ 3. Call a custom action that will rollback the transaction if the message has not been redelivered. (more on this later)
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
@@ -19,7 +18,7 @@
put back onto the queue.
For more details about how this quickstart works look at the
- "What to look at in this Quckstart" section below.
+ "What to look at for this Quckstart" section below.
This quickstart uses jms-jca-provider and more information about jms jca can
be found here: http://wiki.jboss.org/wiki/Wiki.jsp?page=UsingJCAWithJBossESB
@@ -32,24 +31,52 @@
To Run '.esb' archive mode:
===========================
1. In a command terminal window in this folder ("Window1"), type:
- 'ant deploy'
- This will deploy the quickstart
+ 'ant deploy'
+ This will deploy the quickstart
2. Open another command terminal window in this folder ("Window2"), type:
'ant runtest'
3. Switch back to Application Server console to see the output from the ESB
4. In this folder ("Window1"), type:
- 'ant select'
- This will display the content of the database table
- 5. [optional] In this folder ("Window1"), type:
- 'ant truncate'
- This will delete the content of the database table.
- 6. In this folder ("Window1"), type:
- 'ant undeploy'
- This will undeploy the quickstart.
+ 'ant undeploy'
+ This will undeploy the quickstart.
-What to look at in this Quickstart:
+What to look at for this Quickstart:
===================================
- 1. DBInsertAction
+
+ 1. Overall flow of this quickstart:
+ * The first time we enter the action pipleline, we insert a row into the database: (server console output below)
+ [DBInsertAction] Successfully inserted [Hello Transacted JMS World] counter[1]] into jms_transacted_table
+
+ * Next, the RollbackTransactionAction is called.
+ It checks if the ESB Message property 'javax.jms.message.redelivered' is false, in which case
+ the transaction is rolled back, which will also cause the database insert in the preceeding action to be rolled back.
+ If the ESB Message property 'javax.jms.message.redelivered' is true the message will simple pass throw this
+ action unmodified and the action pipeline will complete normally: (server console ouput below)
+ [DBInsertAction] Successfully inserted [Hello Transacted JMS World] counter[2]] into jms_transacted_table
+ [STDOUT] JMS Transacted Quickstart processed sucessfully. Message body:
+
+ * Only the last insert will be committed to the database when the action pipeline successfully completes.
+ In the console output window where 'ant runtest' was run from, the output of the database table is displayed:
+ [echo] Select * from jms_transacted_table
+ [sql] Executing commands
+ [sql] DATA_COLUMN
+ [sql] Hello Transacted JMS World] counter[2]
+ [sql]
+ [sql] 0 rows affected
+ [sql] 1 of 1 SQL statements executed successfully
+ This shows that only the last insert was committed. The other was never written to the database since that transaction
+ was rolled back.
+
+ The value of counter in 'Hello Transacted JMS World] counter[2]' should always match the value in the servers console for
+ the last successfully completed execution of the action pipeline:
+ [DBInsertAction] Successfully inserted [Hello Transacted JMS World] counter[2]] into jms_transacted_table
+ [STDOUT] JMS Transacted Quickstart processed successfully. Message body:
+ [STDOUT] [Hello Transacted JMS World]].
+
+ Note that for successive runs the counter might not be 1 and 2, but by examining the server console you can see which was
+ the last value that was inserted. You may also undeploy and redploy the quickstart and the counter will be reset.
+
+ 2. org.jboss.soa.esb.samples.quickstart.jmstransacted.test.DBInsertAction
Inserts the contents of the ESB Message object into the database table
by using the sql statement defined in the property 'db-insert-sql'.
This class contains a counter that is incremented for each call. This
@@ -60,52 +87,12 @@
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.
+ 3. org.jboss.soa.esb.samples.quickstart.jmstransacted.test.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
+ 4. jboss-esb.xml
The message-filter for the jms-bus-filter now specifies 'transacted' attribute.
- 4. 'ant select'
- Ant target that will display all the rows in the database table.
-
- 5. '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/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/RollbackTransactionAction.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/RollbackTransactionAction.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/RollbackTransactionAction.java 2008-05-19 11:44:30 UTC (rev 20021)
@@ -0,0 +1,82 @@
+/*
+ * 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;
+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 );
+
+ public RollbackTransactionAction( final ConfigTree config )
+ {
+ }
+
+ /**
+ * Will rollback the the current transaction if the rollback
+ * the JMS_REDELIVERED) property is false. 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
+ {
+ final Boolean redelivered = (Boolean) message.getProperties().getProperty( JMS_REDELIVERED );
+ log.info("[" +JMS_REDELIVERED + ":" + redelivered + "]" );
+
+ if ( redelivered )
+ {
+ return message;
+ }
+ else
+ {
+ TransactionStrategy strategy = TransactionStrategy.getTransactionStrategy(true);
+ log.info( "Setting transaction to rollback only" );
+ strategy.rollbackOnly();
+ message = null;
+ }
+ return message;
+ }
+
+ public void processException(final Message message, final Throwable th) { }
+ public void destroy() throws ActionLifecycleException {}
+ public void initialise() throws ActionLifecycleException {}
+
+}
Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/ThrowExceptionAction.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/ThrowExceptionAction.java 2008-05-19 11:36:35 UTC (rev 20020)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/jms_transacted/src/org/jboss/soa/esb/samples/quickstart/jmstransacted/test/ThrowExceptionAction.java 2008-05-19 11:44:30 UTC (rev 20021)
@@ -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