You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Edwin <ed...@gmail.com> on 2012/06/11 18:51:55 UTC

Custom Camel Component instantiated twice

Hi Folks

I am referencing the same camel endpoint from 2 different routes.

E.g.
customcomponent:custom-uri is being referenced from the 2 routes below
from(“customcomponent:custom-uri”).to(…….
from(“file:myfile?fileProperties..”).to(“customcomponent:custom-uri”);

I notice that the corresponding camel component(customcomponent) is
instantiated twice - hence endpoint instantiated twice also.

I would have expected it only to be instantiated once, i.e. component,
endpoint, consumer and producer shared between the 2 different routes.

Could you please confirm whether this behaviour is as expected

Thanks
Edwin


--
View this message in context: http://camel.465427.n5.nabble.com/Custom-Camel-Component-instantiated-twice-tp5714297.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom Camel Component instantiated twice

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Jun 11, 2012 at 11:48 PM, boday <be...@initekconsulting.com>wrote:

> yes, there are multiple Endpoint instances as well (one per route
> reference)...
>
>
No that depends if your endpoint is singleton or not.
If the producer and consumer have the exact uri, then they can share the
same endpoint if its singleton.

And in terms of lifecycle of the Camel components/endpoints/services etc,
then read this
http://camel.apache.org/lifecycle.html




> If you need to share state between instances, then you can define it in the
> Component class and pass into into endpoint/producer/consumer instances via
> constructors. for an example of doing this, see camel-hazelcast, it passes
> around references to hazelcastInstance to its producers/consumers
>
>
> https://svn.apache.org/repos/asf/camel/trunk/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/
>
> otherwise, I suppose you could use class level variables in the
> Endpoint/Consumer/Producer classes as well...
>
>
> gilboy wrote
> >
> > So if there can be multiple Consumer & Producer instances in a given
> > context (one per route reference), this would imply that there could be
> > multiple instance of the Endpoint(again one per route reference)?
> >
> > I have a custom component where I need to share state between the
> producer
> > and the consumer for the same endpoint across different routes. Is this
> > possible?
> >
> > Thanks
> > Joe
> >
>
>
> -----
> Ben O'Day
> IT Consultant -http://consulting-notes.com
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Custom-Camel-Component-instantiated-twice-tp5714297p5714307.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Custom Camel Component instantiated twice

Posted by boday <be...@initekconsulting.com>.
yes, there are multiple Endpoint instances as well (one per route
reference)...

If you need to share state between instances, then you can define it in the
Component class and pass into into endpoint/producer/consumer instances via
constructors. for an example of doing this, see camel-hazelcast, it passes
around references to hazelcastInstance to its producers/consumers

https://svn.apache.org/repos/asf/camel/trunk/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/

otherwise, I suppose you could use class level variables in the
Endpoint/Consumer/Producer classes as well...


gilboy wrote
> 
> So if there can be multiple Consumer & Producer instances in a given
> context (one per route reference), this would imply that there could be
> multiple instance of the Endpoint(again one per route reference)?
> 
> I have a custom component where I need to share state between the producer
> and the consumer for the same endpoint across different routes. Is this
> possible?
> 
> Thanks
> Joe
> 


-----
Ben O'Day
IT Consultant -http://consulting-notes.com

--
View this message in context: http://camel.465427.n5.nabble.com/Custom-Camel-Component-instantiated-twice-tp5714297p5714307.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom Camel Component instantiated twice

Posted by gilboy <jo...@gmail.com>.
So if there can be multiple Consumer & Producer instances in a given context
(one per route reference), this would imply that there could be multiple
instance of the Endpoint(again one per route reference)?

I have a custom component where I need to share state between the producer
and the consumer for the same endpoint across different routes. Is this
possible?

Thanks
Joe

--
View this message in context: http://camel.465427.n5.nabble.com/Custom-Camel-Component-instantiated-twice-tp5714297p5714304.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom Camel Component instantiated twice

Posted by boday <be...@initekconsulting.com>.
your CustomComponent class should only be instantiated once per CamelContext,
but there can be multiple Consumer & Producer instances in a given context
(one per route reference)


Edwin wrote
> 
> Hi Folks
> 
> I am referencing the same camel endpoint from 2 different routes.
> 
> E.g.
> customcomponent:custom-uri is being referenced from the 2 routes below
> from(“customcomponent:custom-uri”).to(…….
> from(“file:myfile?fileProperties..”).to(“customcomponent:custom-uri”);
> 
> I notice that the corresponding camel component(customcomponent) is
> instantiated twice - hence endpoint instantiated twice also.
> 
> I would have expected it only to be instantiated once, i.e. component,
> endpoint, consumer and producer shared between the 2 different routes.
> 
> Could you please confirm whether this behaviour is as expected
> 
> Thanks
> Edwin
> 


-----
Ben O'Day
IT Consultant -http://consulting-notes.com

--
View this message in context: http://camel.465427.n5.nabble.com/Custom-Camel-Component-instantiated-twice-tp5714297p5714302.html
Sent from the Camel - Users mailing list archive at Nabble.com.