在Camel DSL中使用Exchange属性“to”

ecr0jaav  于 2022-12-18  发布在  Apache
关注(0)|答案(3)|浏览(130)

我想在Camel Exchange上设置一个属性,然后在保存文件时使用该属性。在我的Camel dsl中,我有以下内容:

.process(processorToSetExhangeProperty)  // sets the property <uid> on the exchange
.to("file:/tmp?fileName=file-" + property("uid") + ".xml")

文件正在另存为:

"file-property{uid}.xml" though

我的处理器如下:

@Override
public void process(Exchange exchange) throws Exception {
    UUID uuid = UUID.randomUUID();
    exchange.setProperty("uid", uuid.toString());
    exchange.setOut(exchange.getIn());
}


有什么想法可能会出错或我如何才能实现这一点?

hvvq6cgz

hvvq6cgz1#

Camel中的to在运行时不进行解释。
如果你想动态构造你的URI,你应该使用recipientList。

46scxncf

46scxncf2#

已更新接受以上新答案,而不是之前的答案:

答案是[曾经是]:
.to(“文件:/tmp?文件名=文件-${属性.uid}”)+“.xml”)
这个简单的表达式引入了exchange属性。要获得可以引入的内容的完整列表,请参见Simple Expression Language Reference

67up9zun

67up9zun3#

如果需要动态目标,请使用toD()。括号中的表达式使用simple()解释。不需要simple()

toD("file:/tmp?fileName=file-${property.uid}.xml")

但是要注意不要创建太多的端点。
https://camel.apache.org/components/3.18.x/eips/toD-eip.html

相关问题