camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Leuthold <michael.leuth...@gmail.com>
Subject Re: <to "bean:xxx" or not <to "bean:xxx" .... - Getting clarity on bean scope
Date Tue, 29 Jul 2014 20:02:22 GMT
Hi Rickaroni,

from my point of view, I always find it a little disturbing having
state in my services, because from a certain point it makes things
complicated.

To quote the Spring docs:
"The non-singleton, prototype scope of bean deployment results in the
creation of a new bean instance every time a request for that specific
bean is made."

So my guess is you end up having new instances with every method call
because Spring will build a proxy around it and create new instances
with every call.

However, looking at you example I'd rather put the results of that
computation in my message.


Cheers,
Michael




On Tue, Jul 29, 2014 at 5:43 PM, rickaroni <rgfanta@directv.com> wrote:
> Hi Claus et al,
>
> I'd like to use a prototype bean in a route such that a new instance gets
> created at the beginning of the route, and that same instance is used
> throughout the route until the route ends.
>
> Included below are two simple routes and a fragment of a service bean class
> that collects parts from various responses with external services.
>
> [This was somewhat addressed here:
> http://camel.465427.n5.nabble.com/Bean-s-scope-in-Camel-td5737137.html
> before, but not as fully as here.]
>
> Questions:
>  -Is this a legitimate way of keeping state in routes with a service bean,
> or should I be using something else for this use case?
>  -Are ROUTE1 and ROUTE2 completely equivalent?  [If not, why?]
>  -How can I make the same bean instance transfer to ROUTE3?
>  -When will the prototype instance of myAwesomeBean terminate?
>
> Your help is much appreciated!
>
> Rick
>
>
> <beans>
> <bean id="myAwesomeBean" class="com.test.MyAwesomeBean" scope="prototype"/>
>
> <camelContext>
>   <route id = "ROUTE1">
>           <from uri="direct:start"/>
>           <to uri="myAwesomeBean:myBeanMethod1"/>
>           <to uri="http://webService"/>
>           <bean ref="myAwesomeBean" method="myBeanMethod2"/>
>           <to uri="salesforce:doSomething" />
>           <bean ref="myAwesomeBean" method="myBeanMethod3"/>
>           <to uri="direct:ROUTE3">
>   </route>
>
>   <route id = "ROUTE2">
>           <from uri="direct:start"/>
>           <to uri="myAwesomeBean:myBeanMethod1"/>
>           <to uri="http://webService"/>
>           <to uri="myAwesomeBean:myBeanMethod2"/>
>           <to uri="salesforce:doSomething" />
>           <to uri="myAwesomeBean:myBeanMethod3"/>
>           <to uri="direct:ROUTE3">
>   </route>
>
>   <route id ="ROUTE3">
>           <from uri="direct:ROUTE3"/>
>           <to uri="cxf:bean:someOtherService"/>
>           <to uri="myAwesomeBean:myBeanMethod4"/>
>   </route>
> </camelContext>
> <beans>
>
> public class MyAwesomeBean {
>         private String somethingStoredBy_myBeanMethod1 = "";
>         private int somethingStoredBy_myBeanMethod2 = "";
>         private boolean somethingStoredBy_myBeanMethod3 = "";
>         private float somethingStoredBy_myBeanMethod4 = "";
> }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/to-bean-xxx-or-not-to-bean-xxx-Getting-clarity-on-bean-scope-tp5754593.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message