我需要更新Apache Camel中交换属性的帮助。
用例: 我有从API端点获取一些ID的路由,此后,我需要从另一个端点获取每个ID的信息。
我需要将响应保留在某处,以便稍后创建一些JSON数组。
有人可以给我一些具有类似用例的工作路线,还是只是向我指出正确的方向?
答案 0 :(得分:1)
希望这条简单的路线会为您提供帮助:
from("jms://somequeue")
.split(simple("${body}"), (oldExchange, newExchange) -> {
Response response = newExchange.getIn().getBody(Response.class);
LinkedList<Response> responseCollection = oldExchange.getProperty("responseCollection", LinkedList.class);
if (responseCollection == null) {
newExchange.setProperty("responseCollection", new LinkedList<Response>(Collections.singletonList(response)));
} else {
responseCollection.add(response);
newExchange.setProperty("responseCollection", responseCollection);
}
return newExchange;
})
.process(exchange -> {
String id = exchange.getIn().getBody(String.class);
Response response = receiveResponse(id);
exchange.getIn().setBody(response);
})
.end()
.process(exchange -> {
LinkedList<Response> collection = exchange.getProperty("responseCollection", LinkedList.class);
//create your json
});
答案 1 :(得分:0)
您可以使用Simple。 您可以在Exchange API.
上使用setProperty