See code below:
package org.tempuri;
import org.apache.camel.Exchange;
import org.apache.camel.Header;
import org.apache.camel.Message;
import org.apache.camel.processor.aggregate.AggregationStrategy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyAggregationStrategy implements AggregationStrategy {
private static final transient Log LOG =
LogFactory.getLog(MyAggregationStrategy.class);
public Exchange aggregate(Exchange oldExchange, Exchange newExchange)
{
if (oldExchange == null)
{
LOG.info("old is null only new available");
LOG.info("New: " + newExchange);
return newExchange;
}
LOG.info("old: " + oldExchange);
LOG.info("new: " + newExchange);
Message newIn = newExchange.getIn();
String oldBody = oldExchange.getIn().getBody(String.class);
String newBody = newIn.getBody(String.class);
newIn.setBody(oldBody + newBody);
LOG.info("newly formed: " + newExchange);
return newExchange;
}
}
Stan Lewis-3 wrote:
>
> Can you post what you're doing in your aggregation strategy?
>
> On Fri, Jan 22, 2010 at 4:05 AM, lekkie <[email protected]> wrote:
>>
>> Hi,
>>
>> I want to combine messages from 2 different exchanges into a single
>> exchange, from the EIP patterns aggregation strategy seems to be right
>> pattern to use.
>>
>> However, after reading the doc (http://camel.apache.org/aggregator.html),
>> I
>> followed the instructns but my aggregation strategy only returns the last
>> exchange, even though I specifically configured it to send messages only
>> when the outbatchsize is 2.
>>
>> I implemented a custom aggregationstrategy with shoulld combine my
>> exchanges
>> into one. I log the event in the class and it works fine, what is beyond
>> me
>> is why it returns only the last exchange.
>>
>>
>> See my config here:
>> <bean id="myAggregatorStrategy"
>> class="org.tempuri.MyAggregationStrategy"/>
>>
>> <osgi:camelContext xmlns="http://camel.apache.org/schema/spring"
>> trace="true">
>> <route>
>> <from uri="direct:RequestProcessor" />
>> <to uri="xslt:requestToSOAP.xsl"/>
>> <wireTap uri="direct:AggregatorServices"/>
>> <to uri="xslt:requestToManager.xsl"/>
>> <convertBodyTo type="javax.xml.transform.dom.DOMSource" />
>> <to uri="nmr:{http://services.locator/}Service:ServicesPort"/>
>> <to uri="direct:AggregatorServices"/>
>> </route>
>>
>> <route>
>> <from uri="direct:AggregatorServices" />
>> <aggregate strategyRef="myAggregatorStrategy" outBatchSize="2">
>> <correlationExpression>
>> <constant>true</constant>
>> </correlationExpression>
>> <to uri="direct:ProcessorServices"/>
>> </aggregate>
>> </route>
>>
>> <route>
>> <from uri="direct:ProcessorServices" />
>> <to uri="log:Response"/>
>> </route>
>> </osgi:camelContext>
>>
>> log:Response only print out response from <to
>> uri="nmr:{http://services.locator/}Service:ServicesPort"/>.
>>
>> Meanwhile, the log inside myStratRef (myAggregatorStrategy), which I ask
>> to
>> concatenate the old & new exchanges shows both exchanges were
>> concatenated.
>> How do I get this concatenated exchange to be sent (to log:Resposne)?
>>
>> Regards.
>> --
>> View this message in context:
>> http://old.nabble.com/Aggregator%27s-not-returning-combined-exchanges%2C-only-returns-last-exchange-tp27270355p27270355.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context:
http://old.nabble.com/Aggregator%27s-not-returning-combined-exchanges%2C-only-returns-last-exchange-tp27270355p27273231.html
Sent from the Camel - Users mailing list archive at Nabble.com.