You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by 차정호 <jh...@barunmo.com> on 2015/10/28 16:26:59 UTC

How do I maintain custom ojbect in the camel context scope?

Dear Camel developers and users,

 

I like to share some data among routes in the same camel context.

For example, camel context scoped cache object.

 

I know CamelContext have the below methods :

 

package org.apache.camel;

…

public interface CamelContext extends SuspendableService,
RuntimeConfiguration {

…

/**

     * Sets the properties that can be referenced in the camel context

     *

     * @param properties properties

     */

    void setProperties(Map<String, String> properties);

 

    /**

     * Gets the properties that can be referenced in the camel context

     *

     * @return the properties

     */

    Map<String, String> getProperties();

 

But in this case, I cannot add other type value except the String type
value.

So I cannot code like this :

Map<String, String> properties = new HashMap<>();

properties.put(“cache”, new HashMap<String, String>());  <-- compile
error : The method put(String, String) in the type Map<String,String> is
not applicable for the arguments (String, HashMap<String,String>)

camelContext.setProperties(properties);

 

Is there another good solution in this case ?

Thanks a lot before.

 

Jung-Ho Cha,

a Camel rider.

 


Re: How do I maintain custom ojbect in the camel context scope?

Posted by furchess123 <co...@hotmail.com>.
You could always have an application-global object (an instance that lives in
your application context) injected into your Camel processor classes.
Assuming you implement your exchange processing logic in endpoint-specific
POJO "processors", you could wire/inject a reference to that bean into each
such processor, and it will be accessible in your processor code. I would
not over-engineer and clutter your camel context itself. Plus, this would
make your "cache" object application-global and available to other
components/beans, not necessarily only used by Camel routes. 



--
View this message in context: http://camel.465427.n5.nabble.com/How-do-I-maintain-custom-ojbect-in-the-camel-context-scope-tp5773156p5773157.html
Sent from the Camel - Users mailing list archive at Nabble.com.