Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the asciidoc in the repository: https://github.com/apache/camel/blob/master/README.md https://github.com/apache/camel/blob/master/components/readme.adoc
Message exchange patterns and the Exchange object
The MEP defines the messaging style used such as one-way (InOnly) or request-reply (InOut),
The Exchange API provides two methods to get a message, either
Flow of an exchange through a route
Beware of getOut to check if there is an out message
exchange.getOut creates an out message if there is none. So if you want to check if there is an out message then you should use exchange.hasOut instead
Using getIn or getOut methods on Exchange
Now suppose you want to use a Camel Processor to adjust a message. This can be done as follows:
This seems intuitive and is what you would expect is the right approach to change a message from a Processor.
Well that is not all, a Message can also contain attachments so to be sure you need to propagate those as well:
Now we ensure that all additional data is propagated on the new OUT message. But its a shame we need 2 code lines to ensure data is propagated.
Consider using getIn
As shown above you most often need to alter the existing IN message, than creating a totally new OUT message.
Changing the IN message directly is possible in Camel as it doesn't mind. Camel will detect that the Exchange has no OUT message
About Message Exchange Pattern and getOut
So the example code above is possible for any kind of MEP. The MEP is just a flag on the Exchange which the Consumer and Producer adhere to.