camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r674199 - in /activemq/camel/trunk/components/camel-jms/src/test: java/org/apache/camel/component/jms/tx/ resources/org/apache/camel/component/jms/tx/
Date Sat, 05 Jul 2008 13:31:08 GMT
Author: davsclaus
Date: Sat Jul  5 06:31:08 2008
New Revision: 674199

URL: http://svn.apache.org/viewvc?rev=674199&view=rev
Log:
CAMEL-670: TransactionErrorHandler confgured in spring XML

Added:
    activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.java
      - copied, changed from r674158, activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.java
    activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.xml
      - copied, changed from r674158, activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml

Copied: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.java
(from r674158, activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.java?p2=activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.java&p1=activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.java&r1=674158&r2=674199&rev=674199&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.java
(original)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.java
Sat Jul  5 06:31:08 2008
@@ -23,13 +23,13 @@
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
- * Simple unit test for transaction client EIP pattern and JMS.
+ * To demonstrate the TransactionErrorHandlerBuilder configued in Spring XML.
  */
-public class JMSTransactionalClientTest extends SpringTestSupport {
+public class TransactionErrorHandlerBuilderAsSpringBeanTest extends SpringTestSupport {
 
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext(
-            "/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml");
+            "/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.xml");
     }
 
     protected int getExpectedRouteCount() {
@@ -37,7 +37,6 @@
     }
 
     public void testTransactionSuccess() throws Exception {
-        // START SNIPPET: e1
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
         mock.expectedBodiesReceived("Bye World");
@@ -47,10 +46,8 @@
         template.sendBody("activemq:queue:okay", "Hello World");
 
         mock.assertIsSatisfied();
-        // END SNIPPET: e1
     }
 
-    // START SNIPPET: e2
     public static class MyProcessor implements Processor {
         private int count;
 
@@ -62,6 +59,5 @@
             exchange.getIn().setHeader("count", count);
         }
     }
-    // END SNIPPET: e2
 
-}
+}
\ No newline at end of file

Copied: activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.xml
(from r674158, activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.xml?p2=activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.xml&p1=activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml&r1=674158&r2=674199&rev=674199&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml
(original)
+++ activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionErrorHandlerBuilderAsSpringBeanTest.xml
Sat Jul  5 06:31:08 2008
@@ -19,30 +19,72 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:camel="http://activemq.apache.org/camel/schema/spring"
        xsi:schemaLocation="
-        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
-        http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
+         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+         http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
 
     <!-- START SNIPPET: e1 -->
     <!-- here we define our camel context -->
     <camel:camelContext id="myroutes">
         <!-- and now our route using the XML syntax -->
-        <camel:route>
+
+        <!-- here we refer to our transaction error handler we define in this Spring XML
file -->
+        <!-- in this route the transactionErrorHandler is used -->
+        <camel:route errorHandlerRef="transactionErrorHandler">
             <!-- 1: from the jms queue -->
             <camel:from uri="activemq:queue:okay"/>
             <!-- 2: setup the transactional boundaries to require a transaction -->
-            <camel:policy ref="PROPAGATION_REQUIRED"/>
+            <camel:policy ref="required"/>
             <!-- 3: call our business logic that is myProcessor -->
             <camel:process ref="myProcessor"/>
             <!-- 4: if success then send it to the mock -->
             <camel:to uri="mock:result"/>
         </camel:route>
+
+        <!-- this route doens't use error handler, in fact the spring bean  noErrorHandler
-->
+        <camel:route errorHandlerRef="noErrorHandler">
+            <camel:from uri="activemq:queue:bad"/>
+            <camel:to uri="log:bad"/>
+        </camel:route>
+
     </camel:camelContext>
+    <!-- END SNIPPET: e1 -->
 
-    <!-- this bean is our business logic -->
     <bean id="myProcessor" class="org.apache.camel.component.jms.tx.JMSTransactionalClientTest$MyProcessor"/>
-    <!-- END SNIPPET: e1 -->
 
     <!-- START SNIPPET: e2 -->
+    <!-- camel policy we refer to in our route -->
+    <bean id="required" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
+        <property name="template" ref="PROPAGATION_REQUIRED"/>
+    </bean>
+
+    <!-- the standard spring transaction template for required -->
+    <bean id="PROPAGATION_REQUIRED" class="org.springframework.transaction.support.TransactionTemplate">
+        <property name="transactionManager" ref="jmsTransactionManager"/>
+    </bean>
+
+    <!-- the transaction error handle we refer to from the route -->
+    <bean id="transactionErrorHandler" class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
+        <property name="transactionTemplate" ref="PROPAGATION_REQUIRED"/>
+        <!-- here we refer to the configurations of the error handler -->
+        <property name="redeliveryPolicy" ref="redeliveryPolicyConfig"/>
+    </bean>
+
+    <!-- configuration of the transaction error handler -->
+    <bean id="redeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy">
+        <!-- try up till 5 times -->
+        <property name="maximumRedeliveries" value="5"/>
+        <!-- wait 5 seconds at first redelivery -->
+        <property name="initialRedeliveryDelay" value="5000"/>
+        <!-- increas the wait time for each redelivery -->
+        <property name="useExponentialBackOff" value="true"/>
+        <!-- wait at most 30 seconds between redelivery -->
+        <property name="maximumRedeliveryDelay" value="30000"/>
+    </bean>
+
+    <!-- the no error handler -->
+    <bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
+    <!-- END SNIPPET: e2 -->
+
     <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
         <property name="brokerURL" value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
     </bean>
@@ -62,13 +104,4 @@
         <property name="configuration" ref="jmsConfig"/>
     </bean>
 
-    <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
-        <constructor-arg>
-            <bean class="org.springframework.transaction.support.TransactionTemplate">
-                <property name="transactionManager" ref="jmsTransactionManager"/>
-            </bean>
-        </constructor-arg>
-    </bean>
-    <!-- END SNIPPET: e2 -->
-
 </beans>



Mime
View raw message