You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ext2 <xu...@tongtech.com> on 2010/01/13 12:52:10 UTC

How to Understand InOnly and InOut pattern

While learning camel's pattern, it seems the in only patter is very hard to
understand;

Following is a test-case from the camel's unit test( with a little change).
inProcess bean just increase the input message body(as Integer) and set back
to input message. outProcess bean just increase the input message and set
result to output; 

1) following route if using in-out pattern is easy to understand, if I send
a input message number=1, and returned message-exchange's input is 1, output
is 3;
from("direct:a").process(outProcessor).process(outProcessor).to("mock:resul"
);
but using in-only pattern, result message-exchange's input is 3, output is
2. the input is 3, we can understand as if processor doesn't return output,
the input will act as next processor's input, so input is equal 3. but how
to under-stand the output is 2? I think it should be null;

2) following route if using inonly  pattern is easy to understand, if I send
a input message whose body is 1, the result is : in-message is 3,
out-message is null;
from("direct:a").process(inProcessor).process(inProcessor).to("mock:resul");

but if I using in-out pattern, it's hard to understand. The result is
in-message is 2, output-message is 3; how to understand the input-message is
2, I think it should be 1;

Finally what is the real-rule for camel's MEP? Does it means if I use
in-only MEP, the processor should only affect in-message, output message
affect will be unpredictable, and so one for in-out MEP?


final Processor inProcessor = new Processor() { 
            public void process(Exchange exchange) {
                Integer number = exchange.getIn().getBody(Integer.class);
                number = number + 1;
                exchange.getIn().setBody(number);
            }
        };

final Processor outProcessor = new Processor() {
	public void process(Exchange exchange) {
         Integer number = exchange.getIn().getBody(Integer.class);
        number = number + 1;
        exchange.getOut().setBody(number);
     }
};