camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gowtham <>
Subject REG: Aggregator not working fine in camel version 2.8.3
Date Mon, 01 May 2017 04:43:27 GMT
I'm using Spring Framework for IOC in my project. And using Apache-Camel to
deal with reading CSV files marshalling and unmarshalling it. And my
requirement is to merge marshalled data from two CSV Files and store it in a
single file in Output folder. That's when I came across Apache camel
aggregator EIP. I tried to understand it and give it a go.

This is what I have done so far. I have three folders, _input, _intermediate
and _output.
The _input folder contains _input.txt file with some text and similarly
_intermediate folder contains _intermediate.txt with some text. Now in my
route builder I have given like,

		from("file:///C://test//_input").setHeader("myID", constant(1))
			.log("Body from Route1 : ${body}")
		from("file:///C://test//_intermediate").setHeader("myID", constant(1))
			.log("Body from Route2 : ${body}")
		.aggregate( header("myID"), myAggregationStrategy)
			.log("Sending out ${body}")

Where my Aggregation Strategy is like,

	public Exchange aggregate(Exchange aggregatingExchange, Exchange
incomingExchange) {
		if (aggregatingExchange == null) {
			Map<String, Object> headerMap = new
			System.out.println("Header Map : "+headerMap);
			return incomingExchange;   //---------------->Returning null for all
		String oldBody = aggregatingExchange.getIn().getBody(String.class);
		String newBody = incomingExchange.getIn().getBody(String.class);
		String body = oldBody+"\n"+newBody;
		System.out.println("New Body : "+body);
		return aggregatingExchange;

When I try to run the above, both files present in _input and _intermediate
folder are moved to _output folder. When debugging, I come to know that, the
aggregating exchange is null even when it reads second message too. But I
have kept my CorrelationExpression as header("myID") which must group both
my messages from route as a same group. But it's treating as the two
messages belong to completely different group. And also I'm using the camel
version of 2.8.2(core, bindy and test).

Am I missing any step, or is it just the problem with the version of camel.
As I can't go to other versions of camel as it is a business requirement. So
if it is with a version of camel, can you suggest me an alternate way to
achieve the same ?

Gowtham Alaguraj
View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message