You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ben1729 <bm...@scottlogic.co.uk> on 2012/09/18 19:08:52 UTC

Splitting within transactions

I have the following route running in ServiceMix (v4.4.2) using Camel v2.8.5:

from("jms:queue:msci.start")
	.routeId("start-route")
	.transacted()
	.process(new Processor() {
			@Override
			public void process(Exchange exchange) throws Exception {
				List<IGPSUser> users = new ArrayList<IGPSUser>();
				users.add(new GPSUser("id1", "rfyId1", "name1"));
				users.add(new GPSUser("id2", "rfyId2", "name2"));
				users.add(new GPSUser("id3", "rfyId3", "name3"));

				exchange.getIn().setBody(users);

				System.out.println("Completed getting users");
			}
		})
	.split(body())
		 // Simulated crash of ServiceMix
		.process(new Processor() {
			@Override
			public void process(Exchange exchange) throws Exception {
				if (((GPSUser) exchange.getIn().getBody()).getId().equals("id3")) {                        
					// Breakpoint here while I kill ServiceMix using TaskManager
				}
			}                        
		})
		.inOnly("jms:queue:msci.users")
	.end()
;

Messages are then pulled from the users queue for further processing. I am
using a transaction hoping that either all the split messages will get to
the users queue or none of them will (and the message will be rolled back to
the start queue). However, I am seeing that the first two messages get
through and rgwb ServiceMix shuts down. When I restart it (and don't kill at
the breakpoint) all the messages are delivered (including the first two that
got through the first time). What am I doing wrong?



--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-within-transactions-tp5719539.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Splitting within transactions

Posted by "fabrizio.spataro" <fa...@bizmate.it>.
Hello. I have a similar problem.

How to resolve it?



--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-within-transactions-tp5719539p5774114.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Splitting within transactions

Posted by mwojterski <mw...@gmail.com>.
Hi,

I have a similar issue and shareUnitOfWork did not help. I have a route:

<route id="Create">
    <from uri="direct:create"/>

    <onException>
        <exception>java.lang.Exception</exception>
        <rollback markRollbackOnlyLast="true"/>
    </onException>
    <transacted ref="TX_REQ_NEW"/> 

    <split strategyRef="batch-collector" stopOnException="true"
shareUnitOfWork="true">
        <simple>${body.entity}</simple>
        <to uri="db:entity.RootEntity"/>
        <bean ref="create/operation"/>
        <to uri="direct:notify"/>
    </split>
    <bean ref="create/response"/>
</route>

I want this route to start new inner (autonomous) transaction and process
all entities in it.

I tried debugging and what i see is that exchange copied in multicast
processing has indeed UnitOfWork with parent uow set, but only parent has
transactedBy and when my (child) uow is checked in TransactionErrorHandler,
method isTransactedBy returns false and new transaction is opened : (

Please help..



--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-within-transactions-tp5719539p5743789.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Splitting within transactions

Posted by ben1729 <bm...@scottlogic.co.uk>.
Thanks Claus, just the trick.



--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-within-transactions-tp5719539p5719573.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Splitting within transactions

Posted by firpili <so...@hotmail.com>.
Hi Claus ! I am more or less new in Camel .. I would like to do something
similar but with files..

I mean.. I have a XML file like:
<Orders>
<order>
<id>1</id>
<desc>desc 1</desc>
</order>
<order>
<id>2</id>
<desc>dec 2</desc>
</order>
</Orders>

and i want to split it in order to store in a database in a single
transaction.. I mean.. if some Order is wrong during the process no 'order'
of this XML file will be store in the database.. instead of that i would
like to throw an exception or st like that..

Do u thing is enough with this or i need to configure anything in my
database configuration ?
I am a bit lost.

from("direct:myRoute").transacted().split(xpath("Orders/order")).unmarshall(dataFormat).process(My
Processor()).to("jta:com.model.Orders?usePersists=true")

It would be great if someone can help me, thanks!!



--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-within-transactions-tp5719539p5796774.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Splitting within transactions

Posted by Claus Ibsen <cl...@gmail.com>.
You need to enable shareUnitOfWork=true, and also set
stopOnException=true on the splitter
http://camel.apache.org/splitter



On Tue, Sep 18, 2012 at 7:08 PM, ben1729 <bm...@scottlogic.co.uk> wrote:
> I have the following route running in ServiceMix (v4.4.2) using Camel v2.8.5:
>
> from("jms:queue:msci.start")
>         .routeId("start-route")
>         .transacted()
>         .process(new Processor() {
>                         @Override
>                         public void process(Exchange exchange) throws Exception {
>                                 List<IGPSUser> users = new ArrayList<IGPSUser>();
>                                 users.add(new GPSUser("id1", "rfyId1", "name1"));
>                                 users.add(new GPSUser("id2", "rfyId2", "name2"));
>                                 users.add(new GPSUser("id3", "rfyId3", "name3"));
>
>                                 exchange.getIn().setBody(users);
>
>                                 System.out.println("Completed getting users");
>                         }
>                 })
>         .split(body())
>                  // Simulated crash of ServiceMix
>                 .process(new Processor() {
>                         @Override
>                         public void process(Exchange exchange) throws Exception {
>                                 if (((GPSUser) exchange.getIn().getBody()).getId().equals("id3")) {
>                                         // Breakpoint here while I kill ServiceMix using TaskManager
>                                 }
>                         }
>                 })
>                 .inOnly("jms:queue:msci.users")
>         .end()
> ;
>
> Messages are then pulled from the users queue for further processing. I am
> using a transaction hoping that either all the split messages will get to
> the users queue or none of them will (and the message will be rolled back to
> the start queue). However, I am seeing that the first two messages get
> through and rgwb ServiceMix shuts down. When I restart it (and don't kill at
> the breakpoint) all the messages are delivered (including the first two that
> got through the first time). What am I doing wrong?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Splitting-within-transactions-tp5719539.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen