Q:

Correlating messages on two Camel Routes

In my application I have a generic Camel Route such as the following
from("direct:something").to("direct:outgoing")

and then dynamically in my code I deploy another route:
from("direct:outgoing").process(processor)

When flowing from route 1 to route 2 a new Exchange will be created. Is there an idiomatic way to correlate both? Should I set EXCHANGE.Correlation_ID header on the first route before sending it out?

A:

This should definitely all be processed on the one exchange. Run this test and you'll see the same camel Exchange, with the same properties, etc.
public class CamelExchangeTest {
    public static void main(String[] args) throws Exception {
        final Processor showExchangeIdProcessor = new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                System.out.println(exchange.getExchangeId());
            }
        };

        Main camelMain = new Main();
        camelMain.addRouteBuilder(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("timer:foo?period=1s&repeatCount=1")
                        .log("excgabge created!")
                        .process(showExchangeIdProcessor)
                        .to("direct:outgoing")
                ;

                from("direct:outgoing")
                        .log("outgoing!")
                        .process(showExchangeIdProcessor)
                ;
            }
        });
        camelMain.run();
    }
}

Output:
ID-MYPC-55760-1411129552791-0-2
ID-MYPC-55760-1411129552791-0-2

So something else is going on. When you say "direct:outgoing", do you mean exactly that or is it something different - a different component perhaps?
When you say the route is created dynamically, how exactly is that done, and when (and why?)

