Apache Camel 更新交换 属性

Apache Camel update exchange property

我需要一些帮助来更新 Apache Camel 中的交换 属性。

用例: 我有从 API 端点获取一些 ID 的路由,之后我需要从另一个端点获取每个 ID 的信息。

我需要将响应保存在某处,以便稍后创建一些 JSON 数组。

有人可以给我一些类似用例的工作路线,或者只是指出正确的方向吗?

示例路线

from("direct:getIds") .setProperty("ValueToUpdate").constant("") 
.to("endpontWhichReturns ids")
.split().jsonpath("$.Data") .log("${property.xrefCode}") 
.toD("getInfoById) .log("${body}") 
.choice() .when(header("CamelHttpResponseCode").isEqualTo("200")) 
.setProperty("body").body() 
.setProperty("updateBody",method("PrepareUpdate","prepare")) 
.aggregate(property("ValueToUpdate"), new Aggreagation()) 
.to("direct:someEndpoint") .end() .to("mock:nestdo11");

您可以使用 Simple。 您可以在 Exchange API.

上使用 setProperty

希望这条简单的路线对您有所帮助:

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
            });