Issue
I have a process like this to send some queries by body to the next process:
.process(exchange -> {
List<GlossaryDTOResponse[]> glossaries = exchange.getIn().getBody(List.class);
List<String> queries = new ArrayList<>();
queries.add("countries=AF&planttypes=AA&status=DD&language=en-EN&pagesize=1");
queries.add("countries=BF&planttypes=AA&status=DB&language=en-EN&pagesize=1");
List<ActivityIssuesDTO> responses = new ArrayList<>();
// just to send an empity response array to create the final result
Util.setProperty(exchange, "response", responses);
exchange.getIn().setBody(queries);
})
And then i split the body to read each body element:
.split(body())
Then i read the body in each element and send it by HTTP query to a microservice:
.process(exchange -> {
List<GlossaryDTOResponse> glossaryDTOResponses = exchange.getIn().getBody(List.class);
List<ActivityIssuesDTO> responses = exchange.getProperty("response", List.class);
Util.setProperty(exchange, "response", responses);
exchange.getIn().setHeader(Exchange.HTTP_QUERY, glossaryDTOResponses.get(0));
})
.toD(serviceUtils.getActivityEndpoint() + ServiceUtils.ACTIVITIES + Util.BRIDGE_ENDPOINT)
.unmarshal().json(ActivityIssuesDTO.class)
In this process i have my final response in activityIssuesDTO and i send it with body.
.process(exchange -> {
ActivityIssuesDTO activityIssuesDTO = exchange.getIn().getBody(ActivityIssuesDTO.class);
List<ActivityIssuesDTO> activityIssuesDTOs = exchange.getProperty("response", List.class);
activityIssuesDTOs.add(activityIssuesDTO);
exchange.getIn().setBody(activityIssuesDTOs);
})
.marshal().json();
The problem is that i can't see my response and can't marshal it.
Thank you.
I removed the split and for one item(query) it's ok and i can see my response but for many query i can't see my response.
I tried it also with static array and it's the same.
Solution
As I understood it in each Split we need also an aggregator to aggregation our message to continue the process and i resolved it by creating an aggregator and put create the finale result inside my aggregator this result is coming from my micro service.
this is the final result:
.split(body())
.aggregationStrategy(new ActivityAggregator())
.streaming()
.to(direct(GET_QUERY_FINAL))
.end()
and this is my internal route:
from(direct(GET_QUERY_FINAL))
.log("getting the query and send to activity ms")
.process(exchange -> {
String queries = exchange.getIn().getBody(String.class);
List<ActivityIssuesDTO> response = exchange.getProperty("response", List.class);
Util.setProperty(exchange, "response", response);
exchange.getIn().setHeader(Exchange.HTTP_QUERY, queries);
})
.toD(serviceUtils.getActivityEndpoint() + ServiceUtils.ACTIVITIES + Util.BRIDGE_ENDPOINT)
.unmarshal().json(ActivityIssuesDTO.class);
and inside my aggregator i just put the final result inside my new array.
Thanks.
Answered By - Sayed Sajad Hosseini
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.