camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jared O'Connor <>
Subject Message Correlation in Request/Reply
Date Tue, 07 Feb 2012 12:47:57 GMT

I recently encountered an interesting problem, where I needed to set an output message via
an enricher with a dynamic URI or an aggregator. The StackOverflow link below explains the
I discussed this with "cschneide" on IRC, who I believe is a Camel developer, and it would
seem new Camel functionality may need to be investigated. Enabling dynamic URIs on enrichers
is one option, but I would like to suggest an alternative. See below.
Web Service
@Component@Path("/")public class WebService { @GET @Path("files/{id}") public String getFile(@PathParam("id")
String id) {  return null; }}
Aggregation Strategy
@Componentpublic class Aggregator implements AggregationStrategy { public Exchange aggregate(Exchange
oldExchange, Exchange newExchange) {  if (oldExchange == null) {   return newExchange;  }
else {   oldExchange.getOut().setBody(newExchange.getIn().getBody());   return oldExchange;
 } } }
<route> <from uri="cxfrs://bean:webService"/> <choice>  <when>   <simple>${in.headers.operationName}
== 'getFile'</simple>   <setHeader headerName="correlationId">    <simple>mandatoryBodyAs(java.lang.String)</simple>
  </setHeader>   <to uri="seda:aggregation"/>  </when> <choice></route><route>
<from uri="file://someFolder"/> <setHeader headerName="correlationId">  <simple>file:name</simple>
</setHeader> <convertBodyTo type="java.lang.String"/> <to uri="seda:aggregation"/></route><route>
<from uri="seda:aggregation"/> <aggregate completionSize="2" completionTimeout="10000"
strategyRef="aggregator">  <correlationExpression>   <simple>in.headers.correlationId</simple>
 </correlationExpression>  <stop/> </aggregate> <transform>  <simple>${out.body}NOT
AGGREGATED</simple> </transform></route>
The aggregator component currently only handles "InOnly" exchanges. Thus, the routes above
would immediately return "NOT AGGREGATED", rather than returning the file contents after aggregation
has occurred. I suggest allowing aggregators to handle "InOut" exchanges. This solution overkill
for simple correlations that could be achieved via an expression on a polling enricher. However,
this would allow you to respond with messages that have to be read or parsed for the correlation
identifier. In other words, this allows you to use a message from one route as the response
for another.
What are your thoughts?
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message