Loading
 
What's Next: View All Tutorial →

Difference between ExchangePattern.InOut and ExchangePattern.InOnly in Apache camel

In this example you will learn differnce between ExchangePattern.InOut and ExchangePattern.InOnly in Apache camel Router definition from("direct:invokeaddFuntion").bean(Calculator.class, "add10").end(); //to invoke the calu...

Published Date: 04/05/2015  Last Modified Date: 04/05/2015    New Post



In this example you will learn differnce between ExchangePattern.InOut and ExchangePattern.InOnly in Apache camel


Router definition


from("direct:invokeaddFuntion").bean(Calculator.class, "add10").end();
//to invoke the calutor method
public class Calculator {

    public int add10(int a) {
        System.out.println("Method Signature : int add(int a)");
        return a + 10;
    }
}


Invoke with ExchangePattern.InOut


ExchangePattern.InOut - will send the input and response the output
 
 ProducerTemplate producer = context.createProducerTemplate();
 Object res = producer.sendBody("direct:invokeaddFuntion", ExchangePattern.InOut, 1);
 System.out.println(res);


Output:
11
 

Invoke with ExchangePattern.InOnly


ExchangePattern.InOnly  will only pass the input, It will not send the output to the calling funciton
 ProducerTemplate producer = context.createProducerTemplate();
 Object res = producer.sendBody("direct:invokeaddFuntion", ExchangePattern.InOnly, 1);
 System.out.println(res);

Output:
null



 
Awaiting for Administrator approval





Tags: Basic bean component

← Back to list


Related Post




×