[英]Apache Camel file component with dynamic path
我试图在骆驼文件组件中设置动态路径,以避免平台特定的路径。 但是骆驼不允许这样做,因为它不希望目录路径中有$。
我想要做的是设置一个虚拟机参数,例如file.home,然后将其用于我的文件组件中,例如
文件:\\ $ {file.home} \\ TYPE1
这将使我直接消除平台特定的路径。 我尝试将其外部化为属性文件,但是Spring不了解骆驼特定的动态语言,例如$ {in.header.abc}
有人可以帮助我实现这一目标。
以下是有关在骆驼和/或spring xml中使用属性的一些详细信息: http : //camel.apache.org/using-propertyplaceholder.html
您可以使用动态uri,但只能to
端点(使用特定组件)。 您不能from
使用它。
在这里,您可以找到有关如何使用toD
(来自Camel 2.16)或recipientList
: 如何在其中使用动态URI。
但正如我所说-只能将其to
。 这是不可能在使用它from
。 解决方法是,必须为预期使用的每个位置编写一条路由。 您还可以使用autoCreate=false
选项不自动创建其他目录,因为例如,没有autoCreate=false
选项的Linux路径: /home/user/test
将在Windows c:\\home\\user\\test
创建目录结构
自骆驼2.16
我们可以用
.from("file://folder")
.toD("file://folder/${file:onlyname}")
这些答案是不正确的。 如果使用BridgePropertyPlaceholderConfigurer和PropertiesComponent,则可以在任何地方使用动态值。
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="properties">
<value>
...normal property syntax name=value - use this in test definitions
</value>
</property>
</bean>
或在实际应用中使用类似的东西
<bean id="dummyPropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="location" value="classpath:/dummy.properties" />
</bean>
例如
<route id="DummyRoute">
<from uri="file:{{dummy.int.dir}}?delay={{poll.delay}}&initialDelay={{initial.delay}}&{{readlockChanged}}&move={{root}}/{{dummy.arch.dir}}/{{archive.dir}}&moveFailed={{error.dir}}&scheduledExecutorService=#scheduledExecutorService" />
<to uri="file:{{root}}/{{dummy.int.destination.dir}}" />
</route>
Camel的更高版本有一个技巧:使用$simple{file.path}
而不是${file.path}
这样Spring不会剥离${}
并将裸露的file.path传递给Camel。 例如,从“ uri”输入的移动可能是这样的:
move=archive/$simple{date:now:yyyyMMdd}/$simple{file:name}
http://camel.apache.org/how-do-i-use-spring-property-placeholder-with-camel-xml.html
根据骆驼文件组件 :
Camel仅支持配置了起始目录的端点。 因此,directoryName必须是目录。 如果只想使用一个文件,则可以使用fileName选项,例如,通过设置fileName = thefilename。 此外,起始目录不得包含带有$ {}占位符的动态表达式。 再次使用fileName选项指定文件名的动态部分 。
因此,您可以执行以下操作:
from(...).to("file://?fileName=${somePathAndSomeFile}").to(...)
该线程中的某些注释/答案具有误导性,因为可以按要求将“ from”端点URI的值设置为具有从属性文件中获取的目录的值。
将propertyPlaceholder元素放置在camelContext下,并确保可以在类路径中找到属性文件
<propertyPlaceholder location="dir.properties" />
<from id="_fromInputFolder" uri="file:{{fromDir}}?"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.