Camel 蓝图更新 cfg 文件 属性 值

Camel blueprint update cfg file property value

我们有一个每 30 秒有一个调度程序的路由,它从 cfg 属性 文件中读取一个值。如果 属性 键值是 "Y" 那么我们有特定的程序要执行。如果 属性 键值是 'N' 那么我们必须跳过这个过程。 我们有一个管理 Web 应用程序通过 tcp 通信将值发送到 camel 路由。

我的问题是,在从外部应用程序接收值时,我们必须更新 camel 路由中的 cfg 文件值,我们正在接收 camel 路由中的值,但更新我们遇到的 cfg 属性 文件。

我创建了一个测试路由器供参考

<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>

遇到这种情况请指教

假设你的cfg持有key=value格式的问题,你可以通过设置body将数据写入文件。

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

然后您可以使用

等文件组件写入文件
<to uri="file:<path cfg>?filename=myprooperties.cfg&append=true

这将继续向属性添加新条目。为了避免这个问题,您可以将整个文件内容作为映射加载到内存中,更新值并覆盖文件的内容。