skip to Main Content

I need some help with update of exchange property in Apache Camel.

Use case:
I have route which gets some Ids from API endpoint, after that i need to get info for every id from another endpoint.

I need to keep responses somewhere in order to create some JSON array later.

Can someone give me some working route with similar use case or just point me in right direction?

sample route

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

2

Answers


  1. You can use Simple.
    You can use setProperty on the Exchange API.

    Login or Signup to reply.
  2. Hope this simple route will help you:

    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
                });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search