in multi-datasource-2pc/src/main/java/sample/camel/MyCamelRouter.java [49:88]
public void configure() throws Exception {
// route to insert names in the database
// split the list and send each name to be processed
from("timer://runOnce?repeatCount=1&delay=1000")
.id("split")
.setBody(constant(NAMES))
.split(body())
.to("direct:processName");
from("direct:processName")
.transacted()
.id("processName")
.delay(simple("{{myPeriod}}"))
.to("log:info?showAll=true")
.setHeader("name", body())
// prepare the insert SQL
.setBody(simple("insert into names(name) values('${header.name}')"))
.log("insert into the first database (non-unique)")
.to("spring-jdbc:ds1?resetAutoCommit=false")
.log("insert into the second database (unique)")
.to("spring-jdbc:ds2?resetAutoCommit=false");
// route to print inserted names
from("timer:query?period={{myPeriod}}")
.routeId("query1")
.delay(200)
.setBody(constant("select count(*) as \"C\" from names"))
.to("spring-jdbc:ds1")
.setBody(simple("There are ${body[0][C]} names in the ds1 database."))
.to("log:info");
// route to print inserted names
from("timer:query?period={{myPeriod}}")
.routeId("query2")
.delay(200)
.setBody(constant("select count(*) as \"C\" from names"))
.to("spring-jdbc:ds2")
.setBody(simple("There are ${body[0][C]} names in the ds2 database."))
.to("log:info");
}