Loading
 
What's Next: View All Tutorial →

Seda Component - For asynchronous non blocking endpoint router invoking - Apache Camel

In this article, you will lean seda component. Unlike direct component, the seda component will be executed asynchronous non blocking mode.   Camel Program   package com.catchmycity.sedacomponent; /* * To change this license he...

Published Date: 03/06/2015  Last Modified Date: 03/06/2015    New Post



In this article, you will lean seda component. Unlike direct component, the seda component will be executed asynchronous non blocking mode.
 

Camel Program

 
package com.catchmycity.sedacomponent;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

/**
 *
 * @author catchmycity
 */
public class AsynchronousCallUsingSeda {

    public static void main(String args[]) throws Exception {

        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("seda:start").process(new Processor() {

                    @Override
                    public void process(Exchange exchange) throws Exception {
                        Thread.sleep(2000);
                        System.out.println("Inside seda processor");
                    }
                })
                        .end();

                from("direct:start").process(new Processor() {

                    @Override
                    public void process(Exchange exchange) throws Exception {
                        Thread.sleep(2000);
                        System.out.println("Inside direct processor");
                    }
                })
                        .end();
            }
        });

        context.start();
        ProducerTemplate producer = context.createProducerTemplate();

        System.out.println("Before seda call");
        producer.sendBody("seda:start", ExchangePattern.InOnly, "MessageA");

        System.out.println("After seda call");

        System.out.println("Before direct call");
        producer.sendBody("direct:start", ExchangePattern.InOnly, "MessageA");
        System.out.println("After direct call");

    }
}
 

Description

In the direct: component the "After direct call"  statement printed after the processor is executed. Processor wait for 2 s.


In the seda: component the "After seda call" statement printed before the procssor is executed. As it is asynchronous non blocking endpoint router invoking.


OutPut:
 
Before seda call
After seda call
Before direct call
Inside seda processor
Inside direct processor
After direct call


Download

https://github.com/Catchmycity/ApacheCamel/tree/master/ApacheCamel/SedaComponent
 
Awaiting for Administrator approval





Tags: Seda Component

← Back to list


Related Post




×