2
votes

First a basic out line of what I am trying to do

  1. I have a MQ that I want to read messages from
  2. Preprocess the XML, and set a property on the Exchange
  3. Make a HTTP request
  4. Process data from http request and from the property on the initial exchange
  5. Put it on an outbound message Queue

I have been looking around to confirm that each time that a message is read off of the initial MQ that a new Exchange will be created. I haven't been able to find anything that says that explicitly, but I am assuming and was wondering if someone could confirm or deny that is the case.

Is an exchange only used once? And does a route create a new exchange for each message that comes in?

Thanks!

EDIT: And of course my pair then immediately googles and finds the answer. Yes it is unique and we found the documentation on the Exchange API here http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html

1

1 Answers

3
votes

For the most part, an Exchange is created for each consumer thread of a route. The one exception (that I know of) is using the "direct" endpoint, which will reuse an existing Exchange (if one exists already in the request)...

For example, these 2 routes chained together (via direct). The first route will create a new Exchange and will pass it along to the second route (see the logged exchangeId)...

from("direct:route1").log("route1.exchangeId=${exchangeId}").to("direct:route2");
from("direct:route2").log("route2.exchangeId=${exchangeId}");

But, if you were to chain them together with any other component (seda, vm, activemq, etc), then a new Exchange would be created for the 2nd route.

from("seda:route1").log("route1.exchangeId=${exchangeId}").to("seda:route2");
from("seda:route2").log("route2.exchangeId=${exchangeId}");