You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bhushand <bh...@yahoo.co.in> on 2013/04/23 15:14:46 UTC

not getting combined response from aggregator

Hello All
      I am trying to use splitter. I am using splitter first time. Following
is my route

<route>
<from uri="direct:start"></from>
     <split strategyRef="MyAggregationStrategy" parallelProcessing="true">
         <method bean="myBean" method="splitMessage"/>
         <to uri="bean:myService?method=service1/>
         <to uri="bean:myService?method=service2/>
    </split>
</route>

Now as per Camel doc, splitMessage() will help me to split incoming message
and will return a collection of splitted messages. As parallel processing is
enabled, service1() and service2() will be executed simultaneously.
MyAggregationStrategy will help me to aggregate the result from service1()
and service2().
In MyAggregationStrategy, I am trying to combine the result from service1()
and service2(). 
But when I am done with splitter and returning back, it is not giving me
combined result.

Please help me how to get combined result of MyAggregationStrategy in caller
method.




Thanks
Bhushan



--
View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: not getting combined response from aggregator

Posted by Christian Müller <ch...@gmail.com>.
Your understanding is wrong.
Camel will split the messages (m1) into it's interdependent records (r1,
r2, ..., r1000) based on the splitter pattern. Each splitted message can be
processed in parallel by using the parallelProcessing option. For each
message, the endpoints/processors in the split route is called one after
the other.
The aggregator is responsible for aggregating the results of the processed
messages (m1, m2, ..., m1000) at the end of the split route. Make sense?

You can merge the result from your service1 and service2 method call in
service2.

Best,
Christian


On Tue, Apr 23, 2013 at 3:14 PM, bhushand <bh...@yahoo.co.in>wrote:

> Hello All
>       I am trying to use splitter. I am using splitter first time.
> Following
> is my route
>
> <route>
> <from uri="direct:start"></from>
>      <split strategyRef="MyAggregationStrategy" parallelProcessing="true">
>          <method bean="myBean" method="splitMessage"/>
>          <to uri="bean:myService?method=service1/>
>          <to uri="bean:myService?method=service2/>
>     </split>
> </route>
>
> Now as per Camel doc, splitMessage() will help me to split incoming message
> and will return a collection of splitted messages. As parallel processing
> is
> enabled, service1() and service2() will be executed simultaneously.
> MyAggregationStrategy will help me to aggregate the result from service1()
> and service2().
> In MyAggregationStrategy, I am trying to combine the result from service1()
> and service2().
> But when I am done with splitter and returning back, it is not giving me
> combined result.
>
> Please help me how to get combined result of MyAggregationStrategy in
> caller
> method.
>
>
>
>
> Thanks
> Bhushan
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: not getting combined response from aggregator

Posted by bhushand <bh...@yahoo.co.in>.
Can anyone help me please




Thanks
Bhushan



--
View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362p5731386.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: not getting combined response from aggregator

Posted by bhushand <bh...@yahoo.co.in>.
Hi Sachin
     That works for me.
     Thanks a lot 



-Bhushan



--
View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362p5731945.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: not getting combined response from aggregator

Posted by Sachin <sa...@gmail.com>.
Can you try using adding all your response in a list in your aggregation
strategy. It works for me like below:

AggregationStrategy surnameAggregator = new AggregationStrategy() {
            @SuppressWarnings("unchecked")
            public Exchange aggregate(Exchange oldExchange, Exchange
newExchange) {
                debugIn("Surname Aggregator", oldExchange, newExchange);
 
                Exchange answer = newExchange;
 
                if (oldExchange != null) {
                    List<String> brothers =
oldExchange.getIn().getBody(List.class);
                    brothers.add(newExchange.getIn().getBody(String.class));
                    answer = oldExchange;
                } else {
                    List<String>brothers = new ArrayList<String>();
                    brothers.add(newExchange.getIn().getBody(String.class));
                    newExchange.getIn().setBody(brothers);
                }
 
                debugOut("Surname Aggregator", answer);
 
                return answer;
            }
        };
 

You can refer to below link for more agrregation examples:
http://massapi.com/class/ag/AggregationStrategy.html




--
View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362p5731865.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: not getting combined response from aggregator

Posted by bhushand <bh...@yahoo.co.in>.
Hi 
    Any suggestions???



--
View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362p5731861.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: not getting combined response from aggregator

Posted by bhushand <bh...@yahoo.co.in>.
Hi
     Somehow I am able to get response. But what I observed is that, finally
I am getting response for only one or two messages. I am refering to 'Split
aggregate request/reply sample' example given in
http://camel.apache.org/splitter.html.

My Sample code is as:

public class MyBean() {
          public List<MyDTO> splitInput(MyDTO dto) {
               // inparameter MyDTO contains 4 values and I am splitting the
input
               // in a list of 2 MyDTO. I am returing list of 2 MyDTO, each
will contain
               // 2 values.
          }

        public MyDTO process1(MyDTO dto) {
             // Fetching database values using MyDTO
        }

        public MyDTO process2(MyDTO dto) {
            // Fetching database values using MyDTO
        }

 }


public class MyAggregator implements AggregationStrategy {

       public Exchange aggregate(Exchange old, Exchange newEx) {
                  if(old == null) {
                        return newEx;
                  } 

                if(old !=null && newEx != null) {
                      //update old exchange by adding values from newEx
                }

            return old;
       }

}


<route>
    <from uri="direct:start"></from>
    <split parallelProcessing=true strategyRef=MyAggregator>
       <method bean="Mybean" method="splitInput"/>
       <to uri="bean:myBean?method=process1"/>
       <to uri="bean:myBean?method=process1"/>
    </split>
</route>

As per documents, splitinput() will split input and return the list of
MyDTOs. Now here I want each DTO should be processed separately and return
combined response.

How to acheive this, *am I on right track.*
Thanks 
Bhushan



--
View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362p5731796.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: not getting combined response from aggregator

Posted by Christian Müller <ch...@gmail.com>.
Can you share a unit test with us which shows your issue? Than it's much
easier for us to understand what you trying to do and what you are may
doing wrong.
Your described scenario works for us in multiple projects...

Best,
Christian


On Fri, Apr 26, 2013 at 3:24 PM, bhushand <bh...@yahoo.co.in>wrote:

> Hello
>       looking for help
>
>
>
> Thanks
> Bhushan
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362p5731615.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: not getting combined response from aggregator

Posted by bhushand <bh...@yahoo.co.in>.
Hello
      looking for help 



Thanks 
Bhushan



--
View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362p5731615.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: not getting combined response from aggregator

Posted by bhushand <bh...@yahoo.co.in>.
Hi Claus Ibsen/Christian 
            Thanks for the response. Claus Ibsen, you are right I am trying
to implement something similar. Now I am not sure if there is a problem with
aggregator or not. Before returning from aggregator I am checking exchange
which is to be returned. It contains exact same response as per my
requirement. But I am not getting anything when I returned to my caller
bean.

            Following is my aggregator implementation
i) aggregate method contains exchange1 and exchange2 as input parameter.
First time exchange1 will be null and second time both will contain response
ii) when both exchange are not null then by using getIn().getBody() , I am
processing the body of message. 
iii) Here I am combining the response. Setting the combined response in
exchange2 and returning the same.
iv) This combined response I am expecting when returned to caller.
v) I have successfuly used multicast where I implemented same aggregator.
There in caller, I am getting response whatever set  in aggregator.



Thanks 
Bhushan        



--
View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362p5731436.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: not getting combined response from aggregator

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Looks like you use this eip
http://camel.apache.org/composed-message-processor.html

I suggest to double check your custom aggregation strategy what
happens. You can debug / log / print out or whatever, to see what
happens.

And / or use the Camel tracer
http://camel.apache.org/tracer

And if you can, then you can show us your code for that aggregator as
its most likely in there some issue is.


On Tue, Apr 23, 2013 at 3:14 PM, bhushand <bh...@yahoo.co.in> wrote:
> Hello All
>       I am trying to use splitter. I am using splitter first time. Following
> is my route
>
> <route>
> <from uri="direct:start"></from>
>      <split strategyRef="MyAggregationStrategy" parallelProcessing="true">
>          <method bean="myBean" method="splitMessage"/>
>          <to uri="bean:myService?method=service1/>
>          <to uri="bean:myService?method=service2/>
>     </split>
> </route>
>
> Now as per Camel doc, splitMessage() will help me to split incoming message
> and will return a collection of splitted messages. As parallel processing is
> enabled, service1() and service2() will be executed simultaneously.
> MyAggregationStrategy will help me to aggregate the result from service1()
> and service2().
> In MyAggregationStrategy, I am trying to combine the result from service1()
> and service2().
> But when I am done with splitter and returning back, it is not giving me
> combined result.
>
> Please help me how to get combined result of MyAggregationStrategy in caller
> method.
>
>
>
>
> Thanks
> Bhushan
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/not-getting-combined-response-from-aggregator-tp5731362.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen