use of org.apache.camel.spring.spi.SpringTransactionPolicy in project camel by apache.
the class DataSourceSpringRouteBuilder method configure.
public void configure() throws Exception {
// get the required policy
SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
// For spring based transaction, end users are encouraged to use the
// transaction error handler instead of the default DeadLetterChannel.
errorHandler(transactionErrorHandler(required));
// 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");
}
use of org.apache.camel.spring.spi.SpringTransactionPolicy in project camel by apache.
the class TransactionalClientDataSourceLookupTypeTest method createRouteBuilder.
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(SpringTransactionPolicy.class);
// Notice: transactionErrorHandler is in SpringRouteBuilder
if (useTransactionErrorHandler) {
// 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.spi.SpringTransactionPolicy 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.spi.SpringTransactionPolicy in project camel by apache.
the class SqlTransactedRouteTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry reg = super.createRegistry();
db = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY).build();
reg.bind("testdb", db);
DataSourceTransactionManager txMgr = new DataSourceTransactionManager();
txMgr.setDataSource(db);
reg.bind("txManager", txMgr);
SpringTransactionPolicy txPolicy = new SpringTransactionPolicy();
txPolicy.setTransactionManager(txMgr);
txPolicy.setPropagationBehaviorName("PROPAGATION_REQUIRED");
reg.bind("required", txPolicy);
return reg;
}
use of org.apache.camel.spring.spi.SpringTransactionPolicy 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();
}
};
}
Aggregations