camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Max Bridgewater <max.bridgewa...@gmail.com>
Subject Re: Puzzling Synchronization and OnComplete
Date Sat, 31 May 2014 12:18:35 GMT
Hi Claus,

Thanks for your feedback. Let me rewrite the two routes so we put the issue
of in vs. out aside. See below. After this change, the two routes still
produce different results. Synchronization in route2 alters the final
result of the  route while it does not in route1.
I did not expect this and I am having difficulty understanding why this is
the case. My question is thus, what is the meaning of one vs. the other way
of using onCompletion/Syncrhonization. Granted, when you change in.body as
opposed to out.body, neither of them changes the outcome of the route.


Thanks.
Max

        <route id="route1">
            <from uri="restlet:/route1"/>
             <onCompletion onCompleteOnly="true">
                <transform>
                    <groovy>exchange.out.body="haha"</groovy>
                   </transform>
            </onCompletion>
             <transform>
                   <constant>hoho</constant>
               </transform>
        </route>

        <route id="route2">
            <from uri="restlet:/route2"/>
             <transform>
                <groovy>
                    exchange.getUnitOfWork().addSynchronization(
                        new org.apache.camel.spi.Synchronization(){
                        public void
onComplete(org.apache.camel.Exchange exchange){
                                exchange.out.body="haha"
                        }
                        public void     onFailure(org.apache.camel.Exchange
exchange){}
                    }
                )
            </groovy>
            </transform>
             <transform>
                   <constant>hoho</constant>
               </transform>
        </route>



On Sat, May 31, 2014 at 2:52 AM, Claus Ibsen <claus.ibsen@gmail.com> wrote:

> Hi
>
> First about using IN vs OUT see this FAQ
> http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html
>
> you should really just only use IN
>
> On Fri, May 30, 2014 at 9:49 PM, Max Bridgewater
> <max.bridgewater@gmail.com> wrote:
> > Now, this one is really puzzling me. What is the difference between the
> > following two routes? I thought they would produce the same thing.
> >
> > Right now, route1 produces "hoho" while the route2 produces "haha".
> >
> >
> >         <route id="route1">
> >             <from uri="restlet:/route1"/>
> >              <onCompletion onCompleteOnly="true">
> >                 <transform>
> >                     <groovy>exchange.getIn().setBody("haha");
> > exchange.getOut().setBody("haha"); "haha"</groovy>
> >                    </transform>
> >             </onCompletion>
> >              <transform>
> >                    <constant>hoho</constant>
> >                </transform>
> >         </route>
> >
> >         <route id="route2">
> >             <from uri="restlet:/route2"/>
> >              <transform>
> >                 <groovy>
> >                     exchange.getUnitOfWork().addSynchronization(
> >                         new org.apache.camel.spi.Synchronization(){
> >                         public void
> > onComplete(org.apache.camel.Exchange x){
> >                                 x.getOut().setBody("haha");
> >                         }
> >                         public void
> onFailure(org.apache.camel.Exchange
> > exchange){}
> >                     }
> >                 )
> >             </groovy>
> >             </transform>
> >              <transform>
> >                    <constant>hoho</constant>
> >                </transform>
> >         </route>
> >
> >
> >
> >
> >
> > Max.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message