Search code examples
apache-camelapache-karafblueprint-osgiapache-servicemixaries

Dynamic Config Loading in Camel Application Bundle in Karaf 3.0.5


I have a simple Camel Application bundle which is to be deployed in Karaf 3.0.5 under Apache Service Mix 6.1. The configuration file is placed in etc/ directory (let's say it is named as wf.cfg). I want to have the dynamic config change functionality in my application bundle. So that whenever something is changed in wf.cfg it is immediately available to bundle. For this I have added the following in my blueprint.xml

<cm:property-placeholder persistent-id="wf"
    update-strategy="reload">
    <cm:default-properties>
        <cm:property name="env" value="local" />
    </cm:default-properties>
</cm:property-placeholder>

<!-- a bean that uses a blueprint property placeholder -->
<bean id="configBean" class="com.jabong.orchestratorservice.basecomponent.config.ConfigBean">
        <property name="env" value="${env}" />
</bean>

The problem I am facing now is if the update-strategy is set to reload. Then it seems to be reloading the entire bean.

Can someone let me know is there a way I can reload only the configBean not the entire bundle? If I can achieve this then may be I can have some static reference to the config variables inside the configBean which my application bundle can then make use of?

The full blueprint.xml is placed here.


Solution

  • the property-placeholder can have two values for the update-strategy :

    1. reload: The blueprint container is reloaded asynchronously when the properties change. Any property change stops the context (and shutdown camel), and restarts it with the new property. everything is done automatically.
    2. none: Nothing is done. The context is not shutdown (and so camel), but the properties are not injected. The property change are lost

    There is another way to inject properties in Aries-Blueprint, through managed-properties : They decorate a bean definition, and dynamically inject the new property into the bean when the configuration change. There are here two modes : bean-managed (invoke a method when the configuration change) and container-managed (invoke a setter when a property change).

    With this managed-properties you can dynamically intercept change in the configuration, and respond to it, without restarting the blueprint context (and consequently without stopping the camel context).

    However, components in camel are not so dynamics : They read the configuration when an endpoint is created, but that's all. If you want to change the configuration of the route dynamically, it's not easy or impossible. You will have to stop/start the route.