Search code examples
apache-camelblueprint-osgi

Camel blueprint update cfg file property value


We have a route with a scheduler of every 30 seconds, which reads a value from a cfg property file. If the property key value is "Y" then we have certain procedures to perform. If the property key value is 'N' then we have to skip the process. We have an admin web application to send value to camel route thru tcp communication.

My question is while receiving value from the external application we have to update the cfg file value in a camel route, we are receiving the value in camel route but updating the cfg property file we got struck.

I created a test router for reference

<route id="test-route-timer">
        <from uri="timer:foo?period=5s" />
        <setProperty propertyName="callInterfaceProcedure">
            <simple>{{call.interface.procedure}}</simple>
        </setProperty> 
        <log message="${property.callInterfaceProcedure}"/> 
        <setProperty propertyName="callInterfaceProcedure">
            <simple>N</simple>
        </setProperty> 
    </route>

Please advice in this case.


Solution

  • Assuming your cfg holds the problem in key=value format, you can write the data to the file by setting the body.

    <setBody>
      <simple>callInterfaceProcedure={{call.interface.procedure}}</simple>
    </setBody>
    

    and then you can write to the file using file component like

    <to uri="file:<path cfg>?filename=myprooperties.cfg&append=true
    

    This will keep on adding new entries to properties. To circumvent this problem, you can load the whole file contents in the memory as map, update values and overwrite the contents of the file.