Author: davsclaus
Date: Fri Jul 4 05:43:57 2008
New Revision: 674031
URL: http://svn.apache.org/viewvc?rev=674031&view=rev
Log:
CAMEL-667: DeadLetterChannel is bypassed for transacted exchanges
Added:
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/JMSTransactionalClientTest.xml
- copied, changed from r673956,
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/AbstractTransactionTest.xml
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java?rev=674031&r1=674030&r2=674031&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
Fri Jul 4 05:43:57 2008
@@ -103,7 +103,14 @@
return data.sync;
}
- resetMaxDeliveryIfTransacted(exchange);
+ // if the exchange is transacted then let the underlysing system
handle the redelivery etc.
+ // this DeadLetterChannel is only for non transacted exchanges
+ if (exchange.isTransacted() && exchange.getException() != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Transacted Exchange, this DeadLetterChannel is
bypassed: " + exchange);
+ }
+ return data.sync;
+ }
if (exchange.getException() != null) {
Throwable e = exchange.getException();
@@ -174,12 +181,6 @@
}
- public void resetMaxDeliveryIfTransacted(Exchange exchange) {
- if (exchange.isTransacted()) {
- redeliveryPolicy.setMaximumRedeliveries(1);
- }
- }
-
public static boolean isFailureHandled(Exchange exchange) {
return exchange.getProperty(FAILURE_HANDLED_PROPERTY) != null;
}
Added:
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/JMSTransactionalClientTest.java?rev=674031&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.java
(added)
+++
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.java
Fri Jul 4 05:43:57 2008
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jms.tx;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Simple unit test for transaction client EIP pattern and JMS.
+ */
+public class JMSTransactionalClientTest extends SpringTestSupport {
+
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext(
+
"/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml");
+ }
+
+ protected int getExpectedRouteCount() {
+ return 1;
+ }
+
+ public void testTransactionSuccess() throws Exception {
+ // START SNIPPET: e1
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedBodiesReceived("Bye World");
+ // success at 3rd attempt
+ mock.message(0).header("count").isEqualTo(3);
+
+ template.sendBody("activemq:queue:okay", "Hello World");
+
+ mock.assertIsSatisfied();
+ // END SNIPPET: e1
+ }
+
+ public static class MyProcessor implements Processor {
+ private int count;
+
+ public void process(Exchange exchange) throws Exception {
+ if (++count <= 2) {
+ throw new IllegalArgumentException("Forced Exception number "
+ count + ", please retry");
+ }
+ exchange.getIn().setBody("Bye World");
+ exchange.getIn().setHeader("count", count);
+ }
+ }
+
+}
Copied:
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml
(from r673956,
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/AbstractTransactionTest.xml)
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml?p2=activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml&p1=activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/AbstractTransactionTest.xml&r1=673956&r2=674031&rev=674031&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/AbstractTransactionTest.xml
(original)
+++
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionalClientTest.xml
Fri Jul 4 05:43:57 2008
@@ -15,28 +15,42 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">
+<beans xmlns="http://www.springframework.org/schema/beans"
+ 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">
+
+ <!-- START SNIPPET: e1 -->
+ <!-- here we define our camel context -->
+ <camel:camelContext id="myroutes">
+ <!-- and now our route using the XML syntax -->
+ <camel:route>
+ <!-- 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"/>
+ <!-- 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>
+ </camel:camelContext>
+
+ <!-- this bean is our business logic -->
+ <bean id="myProcessor"
class="org.apache.camel.component.jms.tx.JMSTransactionalClientTest$MyProcessor"/>
+ <!-- END SNIPPET: e1 -->
+ <!-- START SNIPPET: e2 -->
<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL"
value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
</bean>
- <bean id="jmsConnectionFactory-1"
class="org.apache.activemq.ActiveMQConnectionFactory">
- <property name="brokerURL"
value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
- </bean>
-
<bean id="jmsTransactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
- <bean id="jmsTransactionManager-1"
class="org.springframework.jms.connection.JmsTransactionManager">
- <property name="connectionFactory" ref="jmsConnectionFactory-1"/>
- </bean>
-
<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
<property name="transactionManager" ref="jmsTransactionManager"/>
@@ -44,46 +58,17 @@
<property name="concurrentConsumers" value="1"/>
</bean>
- <bean id="jmsConfig-1"
class="org.apache.camel.component.jms.JmsConfiguration">
- <property name="connectionFactory" ref="jmsConnectionFactory-1"/>
- <property name="transactionManager" ref="jmsTransactionManager-1"/>
- <property name="transacted" value="true"/>
- <property name="concurrentConsumers" value="1"/>
- </bean>
-
<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="jmsConfig"/>
</bean>
- <bean id="activemq-1" class="org.apache.camel.component.jms.JmsComponent">
- <property name="configuration" ref="jmsConfig-1"/>
- </bean>
-
- <bean id="PROPAGATION_REQUIRED_POLICY"
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>
-
- <bean id="PROPAGATION_NOT_SUPPORTED_POLICY"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
- <constructor-arg>
- <bean
class="org.springframework.transaction.support.TransactionTemplate">
- <property name="transactionManager"
ref="jmsTransactionManager"/>
- <property name="propagationBehaviorName"
value="PROPAGATION_NOT_SUPPORTED"/>
- </bean>
- </constructor-arg>
-
- </bean>
-
- <bean id="PROPAGATION_REQUIRES_NEW_POLICY"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
+ <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"/>
- <property name="propagationBehaviorName"
value="PROPAGATION_REQUIRES_NEW"/>
</bean>
</constructor-arg>
</bean>
+ <!-- END SNIPPET: e2 -->
</beans>