Apache camel to combine multiple REST service responses

I am new to Camel and wondering how I can implement the use case below using Camel,

We have a REST web service and lets say that it has two service operations callA and callB. We now have an ESB in front that intercepts client requests before hitting these actual web service URLs.

Now I'm trying to do something like this - Print the URL in the ESB that the client will actually call. In the ESB, we use the Camel Jetty component, which simply proxies this service call. So let's say that this url will be / my -service / scan /

Now, having received this @ESB request, I want to name these two REST endpoints (callA and callB) β†’ Get their answers - resA and resB β†’ Its combination for one resScan response object β†’ return to the client.

All I have now is

<route id="MyServiceScanRoute">
<from uri="jetty:http://{host}.{port}./my-service/scan/?matchOnUriPrefix=true&amp;bridgeEndpoint=true"/>
<!-- Set service specific headers, monitoring etc. -->  
<!-- Call performScan -->
<to uri="direct:performScan"/>
</route>

<route id="SubRoute_performScan">
<from uri="direct:performScan"/>
<!--  HOW DO I??
Make callA, callB service calls. 
Get their responses resA, resB.
Aggregate these responses to resScan
 -->
</route>
+5
source share
2 answers

I think you unnecessarily complicate the decision. :) In my humble opinion, the best way to name two independent remote web services and combine the results:

The routing for the solution above may look like this:

from("direct:serviceFacade")
  .multicast(new GroupedExchangeAggregationStrategy()).parallelProcessing()
    .enrich("http://google.com?q=Foo").enrich("http://google.com?q=Bar")
  .end();

Exchange, direct:serviceFacadeResponse, Exchange.GROUPED_EXCHANGE, (Google Search ).

direct:serviceFacade Jetty:

from("jetty:http://0.0.0.0:8080/myapp/myComplexService").enrich("direct:serviceFacade").setBody(property(Exchange.GROUPED_EXCHANGE));

HTTP- URL- , ESB Jetty, , .

URL- , . , -.

- , , , - (HTTP, CXFRS, Restlet, RSS ..). .

/ , :

, , onPrepareRef . , , . onPrepareRef Exchange.HTTP_URI HTTP-.

( parallelProcessing, Multicast) REST URL-.

Splitter pattern ( parallelProcessing), , . Exchange.HTTP_URI HTTP. , - .

, Camel . .

URL- REST, , , . , . , ( , ).

+13

Content Enricher.

<from uri="direct:performScan"/>
   <enrich uri="ServiceA_Uri_Here" strategyRef="aggregateRequestAndA"/>
   <enrich uri="ServiceA_Uri_Here" strategyRef="aggregateAandB"/>
</route>

Java (, , - script, Scala/groovy?), ).

bean, org.apache.camel.processor.aggregate.AggregationStrategy, , , :

Exchange aggregate(Exchange oldExchange, Exchange newExchange);

, . , callA callB. , : UseLatestAggregationStrategy UseOriginalAggregationStrategy. .

.

+2

All Articles