use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class TransactionalClientDataSourceMDCTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new SpringRouteBuilder() {
public void configure() throws Exception {
context.setUseMDCLogging(true);
from("direct:okay").routeId("route-a").transacted().process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("route-a", MDC.get("camel.routeId"));
assertEquals(exchange.getExchangeId(), MDC.get("camel.exchangeId"));
assertNotNull(MDC.get("camel.transactionKey"));
}
}).to("log:foo").setBody(constant("Tiger in Action")).bean("bookService").to("log:bar").setBody(constant("Elephant in Action")).bean("bookService");
// marks this route as transacted that will use the single policy defined in the registry
from("direct:fail").routeId("route-b").transacted().process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("route-b", MDC.get("camel.routeId"));
assertEquals(exchange.getExchangeId(), MDC.get("camel.exchangeId"));
assertNotNull(MDC.get("camel.transactionKey"));
}
}).to("log:foo2").setBody(constant("Tiger in Action")).bean("bookService").to("log:bar2").setBody(constant("Donkey in Action")).bean("bookService");
}
};
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class TransactionalClientDataSourceTest method createRouteBuilder.
// END SNIPPET: e4
protected RouteBuilder createRouteBuilder() throws Exception {
// the standard RouteBuilder
return new SpringRouteBuilder() {
public void configure() throws Exception {
// START SNIPPET: e1
// lookup the transaction policy
SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
// Notice: transactionErrorHandler is in SpringRouteBuilder
if (isUseTransactionErrorHandler()) {
// useTransactionErrorHandler is only used for unit testing to reuse code
// for doing a 2nd test without this transaction error handler, so ignore
// this. For spring based transaction, end users are encouraged to use the
// transaction error handler instead of the default DeadLetterChannel.
errorHandler(transactionErrorHandler(required));
}
// END SNIPPET: e1
// START SNIPPET: e2
// set the required policy for this route
from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
// set the required policy for this route
from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Donkey in Action")).bean("bookService");
// END SNIPPET: e2
}
};
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class TransactionalClientWithRollbackTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
// the standard RouteBuilder
return new SpringRouteBuilder() {
public void configure() throws Exception {
// setup the transaction policy
SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
// use transaction error handler
errorHandler(transactionErrorHandler(required));
// must setup policy for each route
from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
// must setup policy for each route
from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").rollback();
}
};
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class TransactionalClientDataSourceAsyncTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new SpringRouteBuilder() {
public void configure() throws Exception {
context.addComponent("async", new MyAsyncComponent());
// use required as transaction policy
SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
// configure to use transaction error handler and pass on the required as it will fetch
// the transaction manager from it that it needs
errorHandler(transactionErrorHandler(required));
// on exception is also supported
onException(IllegalArgumentException.class).handled(false).to("mock:error");
from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").log("Before thread ${threadName}").to("async:bye:camel").log("After thread ${threadName}").setBody(constant("Elephant in Action")).bean("bookService");
from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").log("Before thread ${threadName}").to("async:bye:camel").log("After thread ${threadName}").setBody(constant("Donkey in Action")).bean("bookService");
}
};
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class TransactionalClientDataSourceWithOnExceptionHandledAndRollbackTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new SpringRouteBuilder() {
public void configure() throws Exception {
// use required as transaction policy
SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
// configure to use transaction error handler and pass on the required as it will fetch
// the transaction manager from it that it needs
errorHandler(transactionErrorHandler(required));
onException(IllegalArgumentException.class).handled(true).to("mock:error").rollback();
from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Donkey in Action")).bean("bookService");
}
};
}
Aggregations