You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by TRACK81 <hm...@gmail.com> on 2010/04/29 09:30:17 UTC
We can't avoid race-condition using Camel, Spring/JPA
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.
Re: We can't avoid race-condition using Camel, Spring/JPA
Posted by TRACK81 <hm...@gmail.com>.
We use Oracle AQ... and i think there is only 1 consumer.
Maybe the 1 consumer spawns a thread for each message it receives, thus
allowing multi-threaded race condition between 2 or more spring bean Threads
or is there only 1 thread that will be used for all the messages ?
Thanks in advance...
Claus Ibsen-2 wrote:
>
> 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 <hm...@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
>
>
--
View this message in context: http://old.nabble.com/We-can%27t-avoid-race-condition-using-Camel%2C-Spring-JPA-tp28397461p28399336.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: We can't avoid race-condition using Camel, Spring/JPA
Posted by Claus Ibsen <cl...@gmail.com>.
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 <hm...@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