Search in sources :

Example 1 with MyAsyncComponent

use of org.apache.camel.processor.async.MyAsyncComponent in project camel by apache.

the class AsyncLoopCopyTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            context.addComponent("async", new MyAsyncComponent());
            from("direct:start").to(// Should receive Hello Camel
            "mock:before").to("log:before").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    beforeThreadName = Thread.currentThread().getName();
                }
            }).loop(header("NumberIterations")).copy().to(// Should receive 2x Hello Camel
            "mock:loopIterationStart").to(// Will transform the body to Bye Camel
            "async:bye:camel").to(// Should receive 2x Bye Camel
            "mock:loopIterationEnd").end().process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    afterThreadName = Thread.currentThread().getName();
                }
            }).to("log:after").to(// Should receive 1x Hello Camel (original message)
            "mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MyAsyncComponent(org.apache.camel.processor.async.MyAsyncComponent)

Example 2 with MyAsyncComponent

use of org.apache.camel.processor.async.MyAsyncComponent in project camel by apache.

the class AsyncLoopTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() {
    final Processor loopTest = new LoopTestProcessor(10);
    return new RouteBuilder() {

        public void configure() {
            context.addComponent("async", new MyAsyncComponent());
            from("direct:a").loop(8).to("async:hello:camel?append=true").to("mock:result");
            from("direct:b").loop(header("loop")).to("async:hello:camel?append=true").to("mock:result");
            from("direct:c").loop().xpath("/Hello/@n").to("async:hello:camel?append=true").to("mock:result");
            from("direct:d").loop(2).to("async:hello:camel?append=true").to("mock:result").end().to("mock:last");
            from("direct:e").loop(10).to("async:hello:camel?append=true").process(loopTest).to("mock:result").end().to("mock:last");
        }
    };
}
Also used : Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MyAsyncComponent(org.apache.camel.processor.async.MyAsyncComponent)

Example 3 with MyAsyncComponent

use of org.apache.camel.processor.async.MyAsyncComponent in project camel by apache.

the class EnricherAsyncUnhandledExceptionTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    ShutdownStrategy shutdownStrategy = camelContext.getShutdownStrategy();
    camelContext.addComponent("async", new MyAsyncComponent());
    shutdownStrategy.setTimeout(1000);
    shutdownStrategy.setTimeUnit(TimeUnit.MILLISECONDS);
    shutdownStrategy.setShutdownNowOnTimeout(true);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ShutdownStrategy(org.apache.camel.spi.ShutdownStrategy) MyAsyncComponent(org.apache.camel.processor.async.MyAsyncComponent)

Example 4 with MyAsyncComponent

use of org.apache.camel.processor.async.MyAsyncComponent 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");
        }
    };
}
Also used : SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy) MyAsyncComponent(org.apache.camel.processor.async.MyAsyncComponent)

Example 5 with MyAsyncComponent

use of org.apache.camel.processor.async.MyAsyncComponent in project camel by apache.

the class EnricherSendEventTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    ShutdownStrategy shutdownStrategy = camelContext.getShutdownStrategy();
    camelContext.addComponent("async", new MyAsyncComponent());
    shutdownStrategy.setTimeout(1000);
    shutdownStrategy.setTimeUnit(TimeUnit.MILLISECONDS);
    shutdownStrategy.setShutdownNowOnTimeout(true);
    ManagementStrategy managementStrategy = new DefaultManagementStrategy();
    managementStrategy.addEventNotifier(en);
    camelContext.setManagementStrategy(managementStrategy);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultManagementStrategy(org.apache.camel.management.DefaultManagementStrategy) ManagementStrategy(org.apache.camel.spi.ManagementStrategy) ShutdownStrategy(org.apache.camel.spi.ShutdownStrategy) MyAsyncComponent(org.apache.camel.processor.async.MyAsyncComponent) DefaultManagementStrategy(org.apache.camel.management.DefaultManagementStrategy)

Aggregations

MyAsyncComponent (org.apache.camel.processor.async.MyAsyncComponent)5 CamelContext (org.apache.camel.CamelContext)2 Processor (org.apache.camel.Processor)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 ShutdownStrategy (org.apache.camel.spi.ShutdownStrategy)2 Exchange (org.apache.camel.Exchange)1 DefaultManagementStrategy (org.apache.camel.management.DefaultManagementStrategy)1 ManagementStrategy (org.apache.camel.spi.ManagementStrategy)1 SpringRouteBuilder (org.apache.camel.spring.SpringRouteBuilder)1 SpringTransactionPolicy (org.apache.camel.spring.spi.SpringTransactionPolicy)1