1

Here is the use case that I m trying solve - So this is an extension to the my earlier thread, Apache camel to aggregate multiple REST service responses

I've used a Multicast component with custom aggregation strategy to fork the incoming request to sub requests and aggregate their responses. Everything works fine till this.

Now for one of the use case I want the incoming URL parameters to be passes selectively to some of the sub services. ex:

Incoming request - http://[host]/my-service/scan?foo=a&bar=b&baz=c

My Multicast component looks like this -

<multicast strategyRef="myAggregationStrategy" parallelProcessing="true">
     <to REST_service_1"/>
     <to REST_service_2"/>
</multicast>

I want to pass only foo=a to service_1 endpoint and bar=b&baz=c to service_2 endpoint.

Now, with Multicast the same set of request query parameters are getting passed to both service_1 and service_2. i.e. both service_1 and service_2 will receive foo=a&bar=b&baz=c (entire query params)

Option I m thinking (on high level) -
-to break the incoming url parameters and stick them as a headers then i can selectively use these headers to build CamelHttpQuery header for each individual "to service_call"

-But at the end, the Exchange is going to be shared among all the Multicast endpoints, so will this approach work at all?

-Or should I step back and think about different EIP altogether for this particular use case?

-Or I m thinking in a wrong direction :)

Appreciate the inputs! Thanks!

Community
  • 1
  • 1
Rishi
  • 5,869
  • 7
  • 34
  • 45

1 Answers1

2

You can use the recipient list EIP instead, then you can have 2 different uris for the REST services to call, but sending the same message as the multicast would do.

Recipient list also supports parallel and aggregation.

http://camel.apache.org/recipient-list.html

To compute the 2 uris for the rest services you can use a java bean and do a method call expresison, and just return a String with the 2 endpoints separated by comma (or a String[], or a List etc.)

<recipientList strategyRef="myAggregationStrategy" parallelProcessing="true">
     <method ref="myBean" method="whereToSend"/>
</recipientList>
Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • Thanks for the pointer. I need to read more on this EIP and Bean component. But looks like I can use this info as a lead.. – Rishi Jun 21 '12 at 18:17