Hi Another update on the IN vs OUT when you send in an Exchange.
The ProducerCache that is doing the actual sending when using template or sendTo etc, its basically doing all send X to endpoint. Well I am playing with to let it adhere to the principle Hadrian pointed out. He wanted the IN to be more static. And we cannot get there yet when you do routing as all the processors rely on IN being able to mutate during routing. Anyway my grief is that when you send in an Exchange the result would sometimes be stored on IN and not OUT. What I want it to do always is to store the result in OUT and keep IN as the original input. The code to do this is now a bit more complex than just before // copy the original input Message original = exchange.getIn().copy(); producer.process(exchange); // if no OUT then set current IN as result (except for optional out) if (!exchange.hasOut() && exchange.getPattern() != ExchangePattern.InOptionalOut) { // but only if its not the same as original IN to avoid duplicating it // and to adhere to the fact that there was no OUT result at all if (original.getBody() != null && !original.getBody().equals(exchange.getIn().getBody())) { exchange.setOut(exchange.getIn()); } } // and restore original in exchange.setIn(original); return exchange; What I need to do is to copy the original IN message as it can be mutated during routing. Then after processing I need to set the output on the OUT (and take care of OptionalOut) And as well also take care of the fact that the OUT result could be exactly the same as IN (some Camel processors copy IN to OUT). All together this makes it more consistent to work with sending an Exchange to Camel. IN = original input OUT = the result (if any) Any thoughts on this change? PS: I will not affect radically as people often use sendBody to send a message to Camel and these methods returns a body response. And thus we dont have to juggle with where should we store the response IN or OUT and did we mutate IN and what not. On Fri, Jul 10, 2009 at 7:05 AM, Claus Ibsen<claus.ib...@gmail.com> wrote: > Now that we have opened the box with IN OUT FAULT api changes I would > like to point out issues related to OUT > > Given this code: > > Exchange out = template.send("direct:start", new Processor() { > public void process(Exchange exchange) throws Exception { > exchange.getIn().setBody("Hello World"); > exchange.setPattern(ExchangePattern.InOnly); > } > }); > > And this route: > > from("direct:start").transform(constant("Bye World")); > > What would the expected output of Exchange be? > > The current code asserts this: > > assertEquals("Hello World", out.getIn().getBody()); > assertEquals("Bye World", out.getOut().getBody()); > > That looks fair. The route transforms (= set an OUT body) and we > preserve the original IN. > But the exchange pattern was InOnly but we get data in OUT also? Camel > does not adhere strictly to the patterns. > > > Now what if the route only changes the IN message (setBody only changes IN) > > from("direct:start").setBody(constant("Bye World")); > > What should the expected outcome be? > > Should it be as before? > > assertEquals("Hello World", out.getIn().getBody()); > assertEquals("Bye World", out.getOut().getBody()); > > Or as this: > > assertEquals("Bye World", out.getIn().getBody()); > assertEquals(null, out.getOut().getBody()); > > > Its actually now that easy to get a closure on this one. Either we should > - always store "result" in OUT and copy back the original input to IN > - OR try to adhere the exchange pattern, and store "result" in either > IN or OUT depending on the pattern. > > This is often only a matter when you send an Exchange to Camel. If you > use the sendBody then Camel will extract > the correct result and thus its not a problem here. > > > > > -- > Claus Ibsen > Apache Camel Committer > > Open Source Integration: http://fusesource.com > Blog: http://davsclaus.blogspot.com/ > Twitter: http://twitter.com/davsclaus > -- Claus Ibsen Apache Camel Committer Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus