On 9/11/10 10:03 PM, Christian Müller wrote:
Hello list!
I read Claus, Jonathan and Hadrians book Camel in Action and I studied the
Camel site [1]. I also hat a short conversation with Ade from Progress about
the exchange pattern, but still I have the feeling I doesn't understand all
aspects. May be you can help me to understand it correct. Here are my
questions:
- In the book and the Camel site only the exchange patterns InOut and InOnly
are mentioned but org.apache.camel.ExchangePattern defines the following
exchange patterns: InOnly, RobustInOnly, InOut, InOptionalOut, OutOnly,
RobustOutOnly, OutIn, OutOptionalIn. Should we only use InOut and InOnly?
- If I understood Ade correct, after each processing on a
component/processor the message goes throught the pipieline before it
receives the next component/processor. In the case of an InOut exchange, the
pipeline will copy the out message body, headers and attachments into the in
message. So that in the next component/processor can access these data from
the in message again. If I use the InOnly exchange pattern, the
component/processor will write the response into the in message and the
pipeline has nothing to copy.
The pipeline always uses a new copy of exchange which will create a new
inMessage copy as you described, if you are using InOnly exchange
pattern, pipeline still create a new Exchange and copy the in message
from the first exchange.
The InOnly and InOut exchange patterns always take effect in the
component side, current DefaultExchange will not check the exchange
pattern and will create a new out message which copy from the exchange
in message when you call the Exchange.getOutMessage().
> From the end user perspective it looks like it
doesn't matter, whether to use the InOnly or InOut exchange pattern.
- The only one component I know which handle InOnly and InOut "really"
defferently is the jms-component. It will only send a reply message if the
exchange pattern InOut is used.
- If I use a InOnly exchange for the following routes, I takes also more
than 5 seconds until my templeate.send() method returns. I would expect that
the call returns after the exchange was placed into the next sub route
(after a few milliseconds). My key point here is not to improve the
performance. Only to understand the exchange pattern correct, how the work
and how they are used in the right way...
from("direct:start")
.to("direct:sub");
from("direct:sub")
.process(*new* Processor() {
@Override
*public* *void* process(Exchange exchange) *
throws* Exception {
Thread.*sleep*(5000);
}
})
.to("mock:result");
- Do you have recommendations when to use InOnly and InOut?
There are some description about InOnly and InOut message echange
pattern in the Camel in Action chapter 10, as the sync and async
invocation. You may take a look.
- If we write our own processor which modifies the in message, should they
write the modified body into the out message, if the exchnage is out capable
(and also copy all header and attachments we need for further processing)?
Or should we always modify the in message because it requires less action?
You can modify the in message directly, or do some change on the out
message and the pipeline will pick up the right modified message for
you. The DefaultExchange will create a new out message based on the in
message if you call the Exchange.getOutMessage(), so you don't need to
copy the all the headers and attachments yourself.
- The same question for our own type converters. I know the type converter
is implemented in this way, that it will return the new (converted) object.
But our type converters also have to modify the message header. Should they
also check whether the exchange is out capable and than modify the out (if
out capable) or in (if not out capable) message? Is this the way camel
handels the converted object from the type converter?
I think you just need to make the change on the in message, if you want
to avoid the addition copying (camel will copy the out message from the
in message if you make the change on the out message of the exchange).
[1] http://camel.apache.org/exchange-pattern.html
Thanks in advance for your help and taking time for my questions,
Christian
Willem