Add property to Route (not Exchange)

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

Add property to Route (not Exchange)

Jeff Segal
Is there any facility to add arbitrary properties to Routes rather than
just Exchanges from within a RouteBuilder? I noticed that there are a few
internally managed properties automatically added to each Route (id,
parent, group) but I could not find a hook to set additional ones from a
RouteBuilder.

Thanks,
Jeff
Reply | Threaded
Open this post in threaded view
|

Re: Add property to Route (not Exchange)

Raul Kripalani-2
Hi Jeff,

Could you explain your use case a bit further? It is not clear what you
ultimately want to achieve.

Regards,
Raúl.

On 4 April 2012 18:35, Jeff Segal <[hidden email]> wrote:

> Is there any facility to add arbitrary properties to Routes rather than
> just Exchanges from within a RouteBuilder? I noticed that there are a few
> internally managed properties automatically added to each Route (id,
> parent, group) but I could not find a hook to set additional ones from a
> RouteBuilder.
>
> Thanks,
> Jeff
>
Reply | Threaded
Open this post in threaded view
|

Re: Add property to Route (not Exchange)

Jeff Segal
Sure. I have a system which manages Routes dynamically, which requires some
garbage collection to iterate through all Routes in the CamelContext and
remove any which are deemed no longer necessary. For the sake of
discussion, let's say that I wanted to associate a "color" property with
all Routes built by a particular RouteBuilder. Later on, I want the garbage
collection algorithm to remove "red" Routes after running for 30 minutes
and leave other Routes alone.

The easiest way to accomplish that would be to call a method from the
RouteBuilder which adds a "color" property to each Route it creates, which
I'd then inspect later on. However, the only method I have available to me
is RouteDefinition.setProperty(), which sets properties on the Exchanges
created by the Route, not on the Route itself.

My current work-around is to maintain my own Route-Properties mapping in
memory.

Does this make sense?

On Wed, Apr 4, 2012 at 3:15 PM, Raul Kripalani <[hidden email]> wrote:

> Hi Jeff,
>
> Could you explain your use case a bit further? It is not clear what you
> ultimately want to achieve.
>
> Regards,
> Raúl.
>
> On 4 April 2012 18:35, Jeff Segal <[hidden email]> wrote:
>
> > Is there any facility to add arbitrary properties to Routes rather than
> > just Exchanges from within a RouteBuilder? I noticed that there are a few
> > internally managed properties automatically added to each Route (id,
> > parent, group) but I could not find a hook to set additional ones from a
> > RouteBuilder.
> >
> > Thanks,
> > Jeff
> >
>
Reply | Threaded
Open this post in threaded view
|

).Re: Add property to Route (not Exchange)

hadrian
Kinda. What about convention over configuration and have the color in
the route id (e.g. id="red.something" and if id.startsWith("red.") then
garbage collect. Also keep in mind that the RouteBuilder creates just a
model, not the route themselves.

Hadrian

On 04/04/2012 03:53 PM, Jeff Segal wrote:

> Sure. I have a system which manages Routes dynamically, which requires some
> garbage collection to iterate through all Routes in the CamelContext and
> remove any which are deemed no longer necessary. For the sake of
> discussion, let's say that I wanted to associate a "color" property with
> all Routes built by a particular RouteBuilder. Later on, I want the garbage
> collection algorithm to remove "red" Routes after running for 30 minutes
> and leave other Routes alone.
>
> The easiest way to accomplish that would be to call a method from the
> RouteBuilder which adds a "color" property to each Route it creates, which
> I'd then inspect later on. However, the only method I have available to me
> is RouteDefinition.setProperty(), which sets properties on the Exchanges
> created by the Route, not on the Route itself.
>
> My current work-around is to maintain my own Route-Properties mapping in
> memory.
>
> Does this make sense?
>
> On Wed, Apr 4, 2012 at 3:15 PM, Raul Kripalani<[hidden email]>  wrote:
>
>> Hi Jeff,
>>
>> Could you explain your use case a bit further? It is not clear what you
>> ultimately want to achieve.
>>
>> Regards,
>> Raúl.
>>
>> On 4 April 2012 18:35, Jeff Segal<[hidden email]>  wrote:
>>
>>> Is there any facility to add arbitrary properties to Routes rather than
>>> just Exchanges from within a RouteBuilder? I noticed that there are a few
>>> internally managed properties automatically added to each Route (id,
>>> parent, group) but I could not find a hook to set additional ones from a
>>> RouteBuilder.
>>>
>>> Thanks,
>>> Jeff
>>>
>>
>

--
Hadrian Zbarcea
Principal Software Architect
Talend, Inc
http://coders.talend.com/
http://camelbot.blogspot.com/
Reply | Threaded
Open this post in threaded view
|

Re: ).Re: Add property to Route (not Exchange)

Raul Kripalani-2
In reply to this post by Jeff Segal
I don't suppose you use OSGi? If you do, you can export each route as
an OSGi service assigning your own service properties.

Another possibility is to maintain an application-wide singleton
mimicking a route directory, where you keep a map of route ids and
route properties. Your route builder would publish all constructed
routes to this directory, assigning the relevant properties.

Your GC algorithm would then look into this directory to decide which
ones to prune.

Does that help?

On 4 Apr 2012, at 21:36, Hadrian Zbarcea <[hidden email]> wrote:

> Kinda. What about convention over configuration and have the color in
> the route id (e.g. id="red.something" and if id.startsWith("red.") then
> garbage collect. Also keep in mind that the RouteBuilder creates just a
> model, not the route themselves.
>
> Hadrian
>
> On 04/04/2012 03:53 PM, Jeff Segal wrote:
>> Sure. I have a system which manages Routes dynamically, which requires some
>> garbage collection to iterate through all Routes in the CamelContext and
>> remove any which are deemed no longer necessary. For the sake of
>> discussion, let's say that I wanted to associate a "color" property with
>> all Routes built by a particular RouteBuilder. Later on, I want the garbage
>> collection algorithm to remove "red" Routes after running for 30 minutes
>> and leave other Routes alone.
>>
>> The easiest way to accomplish that would be to call a method from the
>> RouteBuilder which adds a "color" property to each Route it creates, which
>> I'd then inspect later on. However, the only method I have available to me
>> is RouteDefinition.setProperty(), which sets properties on the Exchanges
>> created by the Route, not on the Route itself.
>>
>> My current work-around is to maintain my own Route-Properties mapping in
>> memory.
>>
>> Does this make sense?
>>
>> On Wed, Apr 4, 2012 at 3:15 PM, Raul Kripalani<[hidden email]>  wrote:
>>
>>> Hi Jeff,
>>>
>>> Could you explain your use case a bit further? It is not clear what you
>>> ultimately want to achieve.
>>>
>>> Regards,
>>> Raúl.
>>>
>>> On 4 April 2012 18:35, Jeff Segal<[hidden email]>  wrote:
>>>
>>>> Is there any facility to add arbitrary properties to Routes rather than
>>>> just Exchanges from within a RouteBuilder? I noticed that there are a few
>>>> internally managed properties automatically added to each Route (id,
>>>> parent, group) but I could not find a hook to set additional ones from a
>>>> RouteBuilder.
>>>>
>>>> Thanks,
>>>> Jeff
>>>>
>>>
>>
>
> --
> Hadrian Zbarcea
> Principal Software Architect
> Talend, Inc
> http://coders.talend.com/
> http://camelbot.blogspot.com/
Reply | Threaded
Open this post in threaded view
|

Re: ).Re: Add property to Route (not Exchange)

Jeff Segal
In reply to this post by hadrian
Yeah that would certainly work, but would be less ideal than an arbitrary
property map. I think I'd prefer to manage it myself the way I described in
my work-around.

On Wed, Apr 4, 2012 at 4:35 PM, Hadrian Zbarcea <[hidden email]> wrote:

> Kinda. What about convention over configuration and have the color in the
> route id (e.g. id="red.something" and if id.startsWith("red.") then garbage
> collect. Also keep in mind that the RouteBuilder creates just a model, not
> the route themselves.
>
> Hadrian
>
> On 04/04/2012 03:53 PM, Jeff Segal wrote:
>
>> Sure. I have a system which manages Routes dynamically, which requires
>> some
>> garbage collection to iterate through all Routes in the CamelContext and
>> remove any which are deemed no longer necessary. For the sake of
>> discussion, let's say that I wanted to associate a "color" property with
>> all Routes built by a particular RouteBuilder. Later on, I want the
>> garbage
>> collection algorithm to remove "red" Routes after running for 30 minutes
>> and leave other Routes alone.
>>
>> The easiest way to accomplish that would be to call a method from the
>> RouteBuilder which adds a "color" property to each Route it creates, which
>> I'd then inspect later on. However, the only method I have available to me
>> is RouteDefinition.setProperty(), which sets properties on the Exchanges
>> created by the Route, not on the Route itself.
>>
>> My current work-around is to maintain my own Route-Properties mapping in
>> memory.
>>
>> Does this make sense?
>>
>> On Wed, Apr 4, 2012 at 3:15 PM, Raul Kripalani<[hidden email]>
>>  wrote:
>>
>>  Hi Jeff,
>>>
>>> Could you explain your use case a bit further? It is not clear what you
>>> ultimately want to achieve.
>>>
>>> Regards,
>>> Raúl.
>>>
>>> On 4 April 2012 18:35, Jeff Segal<[hidden email]>  wrote:
>>>
>>>  Is there any facility to add arbitrary properties to Routes rather than
>>>> just Exchanges from within a RouteBuilder? I noticed that there are a
>>>> few
>>>> internally managed properties automatically added to each Route (id,
>>>> parent, group) but I could not find a hook to set additional ones from a
>>>> RouteBuilder.
>>>>
>>>> Thanks,
>>>> Jeff
>>>>
>>>>
>>>
>>
> --
> Hadrian Zbarcea
> Principal Software Architect
> Talend, Inc
> http://coders.talend.com/
> http://camelbot.blogspot.com/
>
Reply | Threaded
Open this post in threaded view
|

Re: ).Re: Add property to Route (not Exchange)

Jeff Segal
In reply to this post by Raul Kripalani-2
I do not use OSGI unfortunately.

The other possibility you describe is more or less exactly what I already
created as a work-around. The main downside to it is that I have to manage
the lifecycle of those properties separately from the Routes themselves
rather than being all bundled together.

On Wed, Apr 4, 2012 at 4:51 PM, Raul Kripalani <[hidden email]> wrote:

> I don't suppose you use OSGi? If you do, you can export each route as
> an OSGi service assigning your own service properties.
>
> Another possibility is to maintain an application-wide singleton
> mimicking a route directory, where you keep a map of route ids and
> route properties. Your route builder would publish all constructed
> routes to this directory, assigning the relevant properties.
>
> Your GC algorithm would then look into this directory to decide which
> ones to prune.
>
> Does that help?
>
> On 4 Apr 2012, at 21:36, Hadrian Zbarcea <[hidden email]> wrote:
>
> > Kinda. What about convention over configuration and have the color in
> > the route id (e.g. id="red.something" and if id.startsWith("red.") then
> > garbage collect. Also keep in mind that the RouteBuilder creates just a
> > model, not the route themselves.
> >
> > Hadrian
> >
> > On 04/04/2012 03:53 PM, Jeff Segal wrote:
> >> Sure. I have a system which manages Routes dynamically, which requires
> some
> >> garbage collection to iterate through all Routes in the CamelContext and
> >> remove any which are deemed no longer necessary. For the sake of
> >> discussion, let's say that I wanted to associate a "color" property with
> >> all Routes built by a particular RouteBuilder. Later on, I want the
> garbage
> >> collection algorithm to remove "red" Routes after running for 30 minutes
> >> and leave other Routes alone.
> >>
> >> The easiest way to accomplish that would be to call a method from the
> >> RouteBuilder which adds a "color" property to each Route it creates,
> which
> >> I'd then inspect later on. However, the only method I have available to
> me
> >> is RouteDefinition.setProperty(), which sets properties on the Exchanges
> >> created by the Route, not on the Route itself.
> >>
> >> My current work-around is to maintain my own Route-Properties mapping in
> >> memory.
> >>
> >> Does this make sense?
> >>
> >> On Wed, Apr 4, 2012 at 3:15 PM, Raul Kripalani<[hidden email]>
>  wrote:
> >>
> >>> Hi Jeff,
> >>>
> >>> Could you explain your use case a bit further? It is not clear what you
> >>> ultimately want to achieve.
> >>>
> >>> Regards,
> >>> Raúl.
> >>>
> >>> On 4 April 2012 18:35, Jeff Segal<[hidden email]>  wrote:
> >>>
> >>>> Is there any facility to add arbitrary properties to Routes rather
> than
> >>>> just Exchanges from within a RouteBuilder? I noticed that there are a
> few
> >>>> internally managed properties automatically added to each Route (id,
> >>>> parent, group) but I could not find a hook to set additional ones
> from a
> >>>> RouteBuilder.
> >>>>
> >>>> Thanks,
> >>>> Jeff
> >>>>
> >>>
> >>
> >
> > --
> > Hadrian Zbarcea
> > Principal Software Architect
> > Talend, Inc
> > http://coders.talend.com/
> > http://camelbot.blogspot.com/
>
Reply | Threaded
Open this post in threaded view
|

Re: Add property to Route (not Exchange)

RubyTuesdayDONO
In reply to this post by Jeff Segal
Jeff,

i can think of two approaches which might help:

whenever possible, i try to map my routing logic onto declarative
orchestrations of Enterprise Integration Patterns [1] to avoid interacting
directly with Camel's API [2], neutral though it may be.  perhaps your
use-case can be satisfied by factoring out common elements into sub-routes
(addressable through SEDA [3] input/outputs), and refactoring any dynamism
into (e.g.) Dynamic Routers [4] and Processors [5].  sometimes the
abstractness of this task can be challenging, but the semantics of the EIPs
are likely to be even more stable than the Camel APIs.  it's also more fun
to not have to perform garbage collection yourself.

another option is the work-around you mentioned - store the properties
somewhere else, keyed on the ID of the route.  when you need the properties
of the Route, you'd just look them up by the Route's ID (which you do
have).  sort of like Claim Check [6], albeit simpler.  if the properties'
value domains are simple enough, they could even be encoded directly in the
Route ID.

[1]: http://camel.apache.org/enterprise-integration-patterns.html
[2]: http://camel.apache.org/hiding-middleware.html
[3]: http://camel.apache.org/seda.html
[4]: http://camel.apache.org/dynamic-router.html
[5]: http://camel.apache.org/processor.html
[6]: http://camel.apache.org/claim-check.html

~ Reuben

On Wed, Apr 4, 2012 at 14:53, Jeff Segal <[hidden email]> wrote:

> Sure. I have a system which manages Routes dynamically, which requires
> some garbage collection to iterate through all Routes in the CamelContext
> and remove any which are deemed no longer necessary. For the sake of
> discussion, let's say that I wanted to associate a "color" property with
> all Routes built by a particular RouteBuilder. Later on, I want the garbage
> collection algorithm to remove "red" Routes after running for 30 minutes
> and leave other Routes alone.
>
> The easiest way to accomplish that would be to call a method from the
> RouteBuilder which adds a "color" property to each Route it creates, which
> I'd then inspect later on. However, the only method I have available to me
> is RouteDefinition.setProperty(), which sets properties on the Exchanges
> created by the Route, not on the Route itself.
>
> My current work-around is to maintain my own Route-Properties mapping in
> memory.
>
Reply | Threaded
Open this post in threaded view
|

Re: Add property to Route (not Exchange)

Claus Ibsen-2
In reply to this post by Jeff Segal
On Wed, Apr 4, 2012 at 9:53 PM, Jeff Segal <[hidden email]> wrote:

> Sure. I have a system which manages Routes dynamically, which requires some
> garbage collection to iterate through all Routes in the CamelContext and
> remove any which are deemed no longer necessary. For the sake of
> discussion, let's say that I wanted to associate a "color" property with
> all Routes built by a particular RouteBuilder. Later on, I want the garbage
> collection algorithm to remove "red" Routes after running for 30 minutes
> and leave other Routes alone.
>
> The easiest way to accomplish that would be to call a method from the
> RouteBuilder which adds a "color" property to each Route it creates, which
> I'd then inspect later on. However, the only method I have available to me
> is RouteDefinition.setProperty(), which sets properties on the Exchanges
> created by the Route, not on the Route itself.
>
> My current work-around is to maintain my own Route-Properties mapping in
> memory.
>

There is a LifecycleStrategy or a EventNotifier you can hook into to
get callbacks when routes is added/remove etc. This may help you keep
the map's up-to-date.


> Does this make sense?
>
> On Wed, Apr 4, 2012 at 3:15 PM, Raul Kripalani <[hidden email]> wrote:
>
>> Hi Jeff,
>>
>> Could you explain your use case a bit further? It is not clear what you
>> ultimately want to achieve.
>>
>> Regards,
>> Raúl.
>>
>> On 4 April 2012 18:35, Jeff Segal <[hidden email]> wrote:
>>
>> > Is there any facility to add arbitrary properties to Routes rather than
>> > just Exchanges from within a RouteBuilder? I noticed that there are a few
>> > internally managed properties automatically added to each Route (id,
>> > parent, group) but I could not find a hook to set additional ones from a
>> > RouteBuilder.
>> >
>> > Thanks,
>> > Jeff
>> >
>>



--
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/