Ganesh
Ganesh

Reputation: 13

Apache camel Restlet producer cached

I am using camel 2.18.0 version.I am facing a issue while using restlet component in SEDA flow. Please find the route details below

from("timer://foo?repeatCount=1")
.to("http4://localhost:8080/pages")
.split(body())
.to("seda:pageConsumer");

from("seda:pageConsumer?concurrentConsumer=5")
.toD("restlet:${in.body}")
.process(enrich());

Details on route:

Issue:

when seda endpoint receives 1st URL all is good i.e. "http://localhost:8080/data?page=1&size=5" rest endpoint is invoked by restlet and expected data is processed in route.

when seda endpoint receives 2nd URL i.e. "http://localhost:8080/data?page=2&size=5" , this where issue starts instead of invoking rest endpoint with "page=2&size=5" as query param, restlet use query param from 1st URL i.e. "page=1&size=5". and issue continues for rest of the urls.

upon debugging i found out that camel caches producer in ProducerCache and producer is cached in a hashmap with endpoint uri as the key.

questions why does camel does not honour query param during caching? is there why to avoid the caching?

Please note i got the code working by changing the url to include page details which is ugly. Currently url looks like http://localhost:8080/data/page/2/size/5.

Upvotes: 0

Views: 621

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55555

If the restlet endpoint is calling the same http url (eg host:port) then it can be slightly better to use a plain to with this host:port as static, and then set a header with the dynamic part.

.setHeader(Exchange.HTTP_QUERY, constant("page1=&size=5"))
.to("http:xxxx")

Then the same endpoint/producer is reused and the header then includes the dynamic part with the query parameters.

There is also a header where you can set the context-path as well on Exchange.

If you keep using toD then you can adjust the size of the cache with the cacheSize option - its the same as on recipient list: http://camel.apache.org/recipient-list.html

Upvotes: 0

Related Questions