Hi,
EJLeVin1 wrote:
> Hi Everyone,
> OK so I have somewhat of a complicated question. I am trying to
> develop an aggregation strategy for a spring remoting pipe within camel.
> Here is the flow:
>
> Request: direct:request -> activemq:topic -> (process)
> Response: (process) -> activemq:topic -> (do custom aggregation) ->
> direct:request
>
> **The request/response is happening in an InOut Pattern**
>
> Ok, so the first question is related to aggregation in an InOut pattern.
> How you you define this within the camel DSL? Normally I would expect an
> InOut pattern to look like a simple from().to(), but I'm not sure how this
> works with aggregation.
>
The InOut ExchangePattern need to be set to the exchange which you will
send to the direct:request endpoint.
Camel ProducerTemplate gives you lots of useful method to do this work.
> The next question is related to how aggregation should work. I guess its
> not as much of a matter of what to look for in the aggregation, as much as
> how from an Exchange I can invoke a spring-remoting call on an object that
> implements the same interface, as well as return the exchange with the
> proper spring remoting response. For example, if I have an interface that
> defines the method List<Long> getResults(), in the aggregator strategy, I
> could have a class that will take these responses, combine them and then
> return the combined List<Long> object. If this is not possible--would it be
> possible to take the spring-remoting call on the processor response side,
> convert it into something like an xml document, combine those documents, and
> then convert it into the appropriate List<Long> spring remoting object
> before the call completes.
>
> I know this probably seems somewhat strange, but I am trying to get camel to
> help me solve some distributed computing problems I'm facing, and I thought
> this would be a cool solution.
Current Camel aggragation don't support this , but I think you can do it
by apply your customer aggragation strategy like this.
public class CustomerAggregationStrategy implements AggregationStrategy
{
private static final transient Log LOG =
LogFactory.getLog(CustomerAggregationStrategy.class);
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
LOG.debug("Get the exchange to aggregate, older: " + oldExchange
+ " newer:" + newExchange);
Message oldMessage;
Message newMessage;
// Now we just aggregate the out message here
oldMessage = oldExchange.getOut();
newMessage = newExchange.getOut();
List list = oldMessage.getBody(List.class);
if (list == null) {
List<Long> mylist = new ArrayList<Long>();
mylist.add(oldMessage.getBody(Long.class));
oldMessage.setBody(myList);
list = myList;
}
list.add(newMessage.getBody(Integer.class));
return oldExchange;
}
}
You can get the List<Long> form the exchange's inMessage from the
processor which behinds the aggregator.
Willem