Search in sources :

Example 1 with SpringTransactionPolicy

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");
}
Also used : SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy)

Example 2 with SpringTransactionPolicy

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
        }
    };
}
Also used : SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy)

Example 3 with SpringTransactionPolicy

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
        }
    };
}
Also used : SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy)

Example 4 with SpringTransactionPolicy

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;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy) EmbeddedDatabaseBuilder(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager)

Example 5 with SpringTransactionPolicy

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();
        }
    };
}
Also used : SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy)

Aggregations

SpringTransactionPolicy (org.apache.camel.spring.spi.SpringTransactionPolicy)9 SpringRouteBuilder (org.apache.camel.spring.SpringRouteBuilder)7 JndiRegistry (org.apache.camel.impl.JndiRegistry)1 MyAsyncComponent (org.apache.camel.processor.async.MyAsyncComponent)1 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)1 EmbeddedDatabaseBuilder (org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder)1