Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
<route>
	<from uri="file://local/router/messages/foo"/>
	<to uri="jms:queue:foo"/>
</route>

 

Dynamic To

Available as of Camel 2.16

There is a new <toD> that allows to send a message to a dynamic computed Endpoint using one or more Expression that are concat together. By default the Simple language is used to compute the endpoint. For example to send a message to a endpoint defined by a header you can do

Code Block
xml
xml
<route>
  <from uri="direct:start"/>
  <toD uri="${header.foo"/>
</route>

And in Java DSL

Code Block
from("direct:start")
  .toD("${header.foo}");

 

You can also prefix the uri with a value because by default the uri is evaluated using the Simple language

Code Block
xml
xml
<route>
  <from uri="direct:start"/>
  <toD uri="mock:${header.foo"/>
</route>

And in Java DSL

Code Block
from("direct:start")
  .toD("mock:${header.foo}");

In the example above we compute an endpoint that has prefix "mock:" and then the header foo is appended. So for example if the header foo has value order, then the endpoint is computed as "mock:order".

You can also use other languages that  Simple such as XPath

Code Block
xml
xml
<route>
  <from uri="direct:start"/>
  <toD uri="xpath:/order/@uri"/>
</route>

This is done by specifying the name of the language followed by a colon.

Code Block
from("direct:start")
  .toD("xpath:/order/@uri");

You can also concat multiple Language(s) together using the plus sign + such as shown below:

Code Block
xml
xml
<route>
  <from uri="direct:start"/>
  <toD uri="jms:${header.base}+xpath:/order/@id"/>
</route>

In the example above the uri is a combination of Simple language and XPath where the first part is simple (simple is default language). And then the plus sign separate to another language, where we specify the language name followed by a colon

Code Block
from("direct:start")
  .toD("jms:${header.base}+xpath:/order/@id");

You can concat as many languages as you want, just separate them with the plus sign

The Dynamic To has a few options you can configure

NameDefault ValueDescription
uri Mandatory: The uri to use. See above
pattern To set a specific Exchange Pattern to use when sending to the endpoint. The original MEP is restored afterwards.
cacheSize Allows to configure the cache size for the ProducerCache which caches producers for reuse. Will by default use the default cache size which is 1000. Setting the value to -1 allows to turn off the cache all together.
ignoreInvalidEndpointfalseWhether to ignore an endpoint URI that could not be resolved. If disabled, Camel will throw an exception identifying the invalid endpoint URI.

 

For more details see

Include Page
Using This Pattern
Using This Pattern