Reputation: 18518
I'd like configure a Camel route where the to(uri)
can be specified at runtime.
I tried the following:
public class Foo extends RouteBuilder {
@Override
public void configure() {
// the URI can point to different hosts
from("direct:start").to(${someUri}");
}
}
and then
ProducerTemplate pt = camelContext.createProducerTemplate();
pt.requestBodyAndHeader("direct:start", "someUri", "http://example.com");
However the above doesn't work (Camel complains about not having a default Endpoint).
What's the best way to go about this?
Upvotes: 2
Views: 12246
Reputation: 1
I simply used curly braces without the '$' before it. Here is what I did:
{headers.reQueueName} instead of ${headers.reQueueName} for the uri and it worked :
<to id="requeue" uri="jmsamq:queue:{headers.reQueueName}"/> here is my implementation :
<route id="_throttleRoute">
<from id="throttleRouteStarter" uri="direct:throttleRouteService"/>
<log id="_Step_5" message="Camel throttle Route Started"/>
<log id="_Step_5_1" message="Camel throttle Route is ${headers.next}"/>
<to id="restThrottleCall" uri="restlet:http://host:port/path"/>
<process id="throttleRouteProcess" ref="throttleServiceProcessor"/>
<choice id="_choice2">`enter code here`
<when id="_when3">
<simple>${headers.next} == 'requeue'</simple>
<to id="requeue" uri="jmsamq:queue:{headers.reQueueName}"/>
<log id="_Step_wait1" message="ReQueue sending to ${headers.reQueueName}"/>
</when>
<when id="_when4">
<simple>${headers.next} == 'process'</simple>
<log id="_logNext" message="Invoking Next Work Unit ${headers.next}"/>
<process id="jBPMRouteProcess" ref="jBPMRouteProcessor"/>
</when>
<otherwise id="_otherwise2">
<log id="_log5" loggingLevel="WARN" message="Next for orderId: ${headers.orderid} not found"/>
</otherwise>
</choice>
</route>
Upvotes: 0
Reputation: 407
Although this question has already been answered, I wanted to share this other option to achieve what you're looking for, in case someone else still wonders how to do it:
There is a new method since Camel 2.16 called "toD" wich basically means a "dynamic to". Here is the official reference documentation.
from("direct:start")
.toD("${someUri}");
In this case, the toD method resolves the argument using the Simple language wich means you can use any property that the language supports.
You can also take a look at this other StackOverflow answer, about that same topic.
Upvotes: 4
Reputation: 21005
see these links for reference:
http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html
http://camel.apache.org/recipient-list.html
for an example, see this unit test
Upvotes: 3