Apache camel to aggregate multiple REST service responses

前端 未结 2 2040
你的背包
你的背包 2020-12-15 01:27

I m new to Camel and wondering how I can implement below mentioned use case using Camel,

We have a REST web service and lets say it has two service operations callA

2条回答
  •  情书的邮戳
    2020-12-15 01:49

    This looks like a good example where the Content Enricher pattern should be used. Described here

    
       
       
    
    

    The aggregation strategies has to be written in Java (or perhaps some script language, Scala/groovy? - but that I have not tried).

    The aggregation strategy just needs to be a bean that implements org.apache.camel.processor.aggregate.AggregationStrategy which in turn requires you to implement one method:

    Exchange aggregate(Exchange oldExchange, Exchange newExchange);
    

    So, now it's up to you to merge the request with the response from the enrich service call. You have to do it twice since you have both callA and callB. There are two predefined aggregation strategies that you might or might not find usefull, UseLatestAggregationStrategy and UseOriginalAggregationStrategy. The names are quite self explainatory.

    Good luck

提交回复
热议问题