Permalink
Browse files

Add Tx behavior in Camel route

  • Loading branch information...
1 parent 066494f commit a85dcaaf9a561ff0b57b3e8bef59436466bb7a8f @cmoulliard committed Nov 8, 2011
View
4 README
@@ -34,7 +34,7 @@ H2 DATABASE
Next click on "connect" and the screen to manage the reportdb appears
- STEP 5 : Create Schema and Tables using the script located in the file reportincident.db/src/main/config/h2-script.sql
+ STEP 5 : Create Schema and Tables using the script located in the file db/src/main/config/h2-script.sql
Execute the scripts 1), 2) and 3) defined in this file
@@ -48,7 +48,7 @@ DEPLOYING
STEP 3 : Open in a DOS windows or Unix terminal the directory bin
STEP 4 : Edit the file /etc/org.apache.karaf.features.cfg and add the following features to boot
- featuresBoot=karaf-framework,config,war,activemq-broker,activemq-spring,camel,camel-cxf,camel-activemq,camel-nmr,camel-jaxb,camel-bindy,jpa
+ featuresBoot=karaf-framework,config,war,activemq-broker,activemq-spring,camel,camel-cxf,camel-activemq,camel-jaxb,camel-bindy,jpa
STEP 5 : Start ServiceMix servicemix.bat or ./servicemix
STEP 6 : In the servicemix console, launch the commands to install features of reportincident demo
@@ -36,32 +36,45 @@
http://www.springframework.org/schema/osgi-compendium
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">
-
+ <!-- CXFbeans required to setup Web Service -->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
+ <!-- Properties externalised in org.fusesource.devoxx.reportincident.routing.cfg file -->
<context:property-placeholder properties-ref="camelProps"/>
+ <osgix:cm-properties id="camelProps" persistent-id="org.fusesource.devoxx.reportincident.routing"/>
+ <!-- ActiveMQ component -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory">
<osgi:reference interface="javax.jms.ConnectionFactory"/>
</property>
+ <property name="transacted" value="true"/>
+ <property name="transactionManager">
+ <osgi:reference interface="org.springframework.transaction.PlatformTransactionManager"/>
+ </property>
</bean>
-
- <bean id="bindyDataFormat" class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
- <constructor-arg value="org.fusesource.devoxx.reportincident.model"/>
- </bean>
-
+ <!-- Beans used by Camel -->
<bean id="incidentSaver" class="org.fusesource.devoxx.reportincident.internal.IncidentSaver">
<property name="incidentService">
<osgi:reference interface="org.fusesource.devoxx.reportincident.service.IncidentService"/>
</property>
</bean>
+
<bean id="webservice" class="org.fusesource.devoxx.reportincident.internal.WebService"/>
<bean id="feedback" class="org.fusesource.devoxx.reportincident.internal.Feedback"/>
- <!-- webservice endpoint -->
+ <!-- Tx Manager -->
+ <osgi:reference id="txManager" filter="(tx=JPA)" interface="org.springframework.transaction.PlatformTransactionManager"/>
+
+ <!-- PROPAGATION used for Transactions-->
+ <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
+ <property name="transactionManager" ref="txManager"/>
+ <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
+ </bean>
+
+ <!-- webservice endpoint -->
<cxf:cxfEndpoint id="reportIncident"
address="http://localhost:8282/cxf/camel-example/incident"
serviceClass="org.fusesource.devoxx.reportincident.ReportIncidentEndpoint"
@@ -70,6 +83,10 @@
<camelContext trace="true" xmlns="http://camel.apache.org/schema/spring">
+ <dataFormats>
+ <bindy type="Csv" id="bindyDataFormat" packages="org.fusesource.devoxx.reportincident.model"/>
+ </dataFormats>
+
<route id="fileToQueueIn">
<from uri="file://data/reportincident/?move=backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"/>
<setHeader headerName="origin">
@@ -81,6 +98,7 @@
<route id="queueIntoIncidentSaver">
<from uri="activemq:queue:in"/>
+ <transacted ref="PROPAGATION_REQUIRED"/>
<to uri="bean:incidentSaver?method=process"/>
</route>
@@ -95,10 +113,8 @@
<transform>
<method bean="feedback" method="setOk"/>
</transform>
-
</route>
- </camelContext>
- <osgix:cm-properties id="camelProps" persistent-id="org.fusesource.devoxx.reportincident.routing"/>
+ </camelContext>
</beans>
@@ -31,7 +31,7 @@ public void configure() throws Exception {
// first part from the webservice -> file backup
from(cxfEndpoint)
- // we need to convert the CXF payload to InputReportIncident that FilenameGenerator and velocity expects
+ // we need to convert the CXF payload to InputReportIncident
.convertBodyTo(InputReportIncident.class)
// return OK as response
.transform(constant(OK));
@@ -58,7 +58,7 @@
<property name="transactionAttributes">
<props>
- <prop key="*">PROPAGATION_REQUIRES_NEW</prop>
+ <prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

0 comments on commit a85dcaa

Please sign in to comment.