camel http endpoint forming url dynamically
18,389
Solution 1
See this FAQ about dynamic to endpoints in Camel: https://camel.apache.org/manual/latest/faq/how-to-use-a-dynamic-uri-in-to.html
Solution 2
From camel 2.16 you can do things like this -
from("direct:start")
.toD("${header.foo}");
Refer : http://camel.apache.org/message-endpoint.html
Solution 3
You can use camel property place holder
http://camel.apache.org/using-propertyplaceholder.html
<camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder location="config/AuditJMSConfig.properties" id="properties" />
<route id="crudRoute">
<from uri="activeMQ:queue:{{speedwing.activemq.auditqueue}}/>
</route> where speedwing.activemq.auditqueue is the property name defined in the peroperties file.
you can use the same for <to uri="" also
Related videos on Youtube
Author by
Subodh Gupta
Updated on June 09, 2022Comments
-
Subodh Gupta about 2 years
Guys I am trying to use
{ from("direct:a").to (someUrl).processor(new Processor(){ @Override public void process(Exchange arg0) throws Exception { // do something } }); where someUrl is of the type http://xyz.com/{id}?test=<value1>&test1=<value2> }
and this url will change on every request to the route.
What i have already tried. Passing params as headers and try to access in the route using the header("test") and using ${in.header.test} both doesn't seem to work.
any suggestions will be greatly helpful.
-
Claus Ibsen over 11 yearsRead the FAQ again! You cannot use dynamic values in TO, you should use RECIPIENT LIST instead.
-
Subodh Gupta over 11 yearsI know the question is already got answered but will it be a right way of using the camel (is it a anti-pattern)? Because eip not mean the same usage here: enterpriseintegrationpatterns.com/RecipientList.html
-
Claus Ibsen over 11 yearsIt is certainly not an anti pattern. The EIP is to route a message to a dynamic list of recipients. Which is what the Camel implementation does. And a list of recipients can be 1..n recipients.
-
Subodh Gupta over 11 yearsthanks @claus. Is there any other way to make a remote (not exposed by us) RESTful calls having path-params. I guess only other comes to my mind is setting HTTP_URI header which will override the to endpoint's value. Which one is better in terms of ideal camel usage.
-
Claus Ibsen over 11 yearsSee the Camel components as there is also some REST components among them: camel.apache.org/components
-
vashishth over 10 yearsis there a way to make <from uri="" also dynamic ??
-
Harshit almost 5 yearsUpdated link camel.apache.org/manual/latest/faq/…