[英]How to add matchOnUriPrefix on existing Camel Jetty REST routes?
[英]Camel aggregation with REST routes
我有一個Camel應用程序,我正在嘗試根據不同響應(REST Web服務)的一些輸出進行一些聚合。
這是我到目前為止(Camel路線):
@Component
public final class AggregationRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
rest("/aggregation")
.get()
.to("direct:retrieve");
from("direct:retrieve")
.multicast(/*new BodyAggregationStrategy(), true*/)
.to("direct:foo")
.to("direct:foo1");
from("direct:foo")
.to("seda:http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?sector=conus")
.to("direct:aggregate");
from("direct:foo1")
.to("seda:http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?sector=conus")
.to("direct:aggregate");
from("direct:aggregate")
.aggregate(header("id"), new BodyAggregationStrategy())
.log(LoggingLevel.WARN, simple("${body}").getText());
}
}
......“聚合策略”
public final class BodyAggregationStrategy implements AggregationStrategy {
@Override
public Exchange aggregate(final Exchange oldExchange, final Exchange newExchange) {
if (null == oldExchange) {
return newExchange;
}
String oldBody = oldExchange.getIn().getBody(String.class);
String newBody = newExchange.getIn().getBody(String.class);
oldExchange.getIn().setBody(oldBody + "+" + newBody);
return oldExchange;
}
}
...最終,Web服務將會有所不同,但我現在正試着看看我是否可以先解決這個基本問題。
我定義了一個REST端點,當GET /aggregation
命中時(在我這邊 ),我想咨詢兩個或更多REST Web服務並匯總這些響應; 然后“回答”回來。
有線索嗎?
多播EIP具有內置聚合器,因此在此模式上配置聚合策略,而不是使用單獨的聚合器。 這可以確保消息被變換並作為同一工作單元的一部分進行聚合,結果可以顯示並發送回調用REST客戶端。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.