not getting combined response from aggregator

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

not getting combined response from aggregator

bhushand
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
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

bhushand
Can anyone help me please




Thanks
Bhushan
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

Christian Mueller
Administrator
In reply to this post by bhushand
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 <[hidden email]>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.
>
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

Claus Ibsen-2
In reply to this post by bhushand
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 <[hidden email]> 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: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

bhushand
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        
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

bhushand
Hello
      looking for help



Thanks
Bhushan
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

Christian Mueller
Administrator
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 <[hidden email]>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.
>
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

bhushand
This post was updated on .
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=process2"/>
    </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
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

bhushand
Hi
    Any suggestions???
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

Sachin
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
Reply | Threaded
Open this post in threaded view
|

Re: not getting combined response from aggregator

bhushand
Hi Sachin
     That works for me.
     Thanks a lot



-Bhushan