camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: We can't avoid race-condition using Camel, Spring/JPA
Date Thu, 29 Apr 2010 09:00:24 GMT
Hi

And you are sure you only have 1 consumer from the Oracle JMS queue?
If so then you ought to only have one message being processed at any
time.
Check you JMS configuration and see if concurrentConsumers=1.


On Thu, Apr 29, 2010 at 9:30 AM, TRACK81 <hmubiz@gmail.com> wrote:
>
> Hi
>
> Im have the following problem:
>
> We can't avoid race-condition using Camel, Spring and Jpa
>
> Setup:
>
> We have a Camel Spring supported test where we put two messages on the
> MYELEMENTS queue right after eachother
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////
>        @Test
>        public void testputMyXmlFileOnQueue() throws Exception {
>                putMyXmlFileOnQueue("my1_dublet.xml");
>                putMyXmlFileOnQueue("my2_dublet.xml");
>                Thread.sleep(15000);
>        }
>
>
>        private void putMyXmlFileOnQueue(final String fileName) throws Exception {
>
>        RouteBuilder routeBuilder  = new RouteBuilder() {
>            @Override
>            public void configure() throws Exception {
>                from("file:src/test/data/?fileName=" + fileName +
> "&noop=true").to("oracleQueue:queue:MYELEMENTS?jmsMessageType=Bytes");
>            }
>        };
>        context.addRoutes(routeBuilder);
>    }
> //////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Using the following : Camel context
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xmlns:camel="http://camel.apache.org/schema/spring"
>        xsi:schemaLocation="http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring-2.1.0.xsd
>                http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
>        <bean id="PROPAGATION_REQUIRED"
> class="org.apache.camel.spring.spi.SpringTransactionPolicy">
>        <property name="transactionManager" ref="transactionManager"/>
>        <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
>        </bean>
>
>        <camel:camelContext id="camel">
>                <camel:route trace="true" id="MyNotificationRoute">
>                        <camel:from uri="oracleQueue:queue:MYELEMENTS?jmsMessageType=Bytes"/>
>                        <camel:setExchangePattern pattern="InOnly"/>
>                        <camel:transacted ref="PROPAGATION_REQUIRED"/>
>                        <camel:wireTap uri="seda:audit"/>
>                        <camel:onException>
>                                <camel:exception>java.lang.Exception</camel:exception>
>                                <camel:to uri="mock:error"/>
>                        </camel:onException>
>                        <camel:unmarshal ref="jaxbobjs"/>
>                        <camel:bean ref="MyNotificationService"
> method="handleMyNotificationEvent"/>
>                        <camel:to uri="mock:result"/>
>                </camel:route>
> ......
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Camel will take the messages of the Queue and pass it to
> MyNotificationService.handleMyNotificationEvent
>
> handleMyNotificationEvent is a method that will delete all existing data in
> a table and insert 14 rows based on the message
>
> MyNotificationService is @Transactional, but as we are using JPA it is not
> possible to set the isolation level
>
> The messages will interfere with each-other as they come right after
> eachother and the
> handleMyNotificationEvent will end up having writte 18 rows
>
> The Question is can one setup camel so it will only take a message of the
> queue after a @Transactional Service call
> (MyNotificationService.handleMyNotificationEvent) is finished, thus avoiding
> a race condition???
>
>
> Thanks in Advance...
>
>
> --
> View this message in context: http://old.nabble.com/We-can%27t-avoid-race-condition-using-Camel%2C-Spring-JPA-tp28397461p28397461.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message