使用Content Enricher提供Aggregation Strategy
,像下面:
@Component
MyAggregationStrategy implements AggregationStrategy {
public static final String PRE_ENRICH_KEY = "PRE_ENRICH_KEY";
//this is meant to be called *before* the actual enrich call
//to store the state before the enrichment
public void init(Exchange exchange) {
final String originalBody = exchange.getIn().getBody(String.class);
exchange.setProperty(PRE_ENRICH_KEY, originalBody);
}
@Override
public Exchange aggregate(Exchange original, Exchange enrichmentResponse) {
final String originalBody = original.getProperty(PRE_ENRICH_KEY, String.class);
//enrichmentResponse is the Exchange coming from the 2nd file endpoint
//the enricher returns
//your processing logic to merge the 2 happens here
String result = //..
original.getIn().setBody(result);
return original;
}
}
最後的路徑看起來像:
@Component
public class MyRouteBuilder extends RouteBuilder {
@Autowired
private MyAggregationStrategy myAggregateStrategy;
@Override
public void configure() throws Exception {
from("fileEndpoint1")
.bean(myAggregateStrategy, "init")
.enrich("fileEndpoint2", myMerger);
//continue from here one to Bindy
}
//..
}
感謝您的回覆。我會嘗試在sdping DSL方式 –
@Harish Malavade - 如果你覺得這個有用,請考慮upvoting和/或接受答案 – dimitrisli