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

2022-01-19 00:00:00 java apache-camel

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

I want to set a property on a Camel Exchange and then use this property when saving the file. In my camel dsl I have the following:

.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());
}

对可能出现的问题或如何实现这一点有任何想法吗?

Any thoughts on what may be going wrong or how I can achieve this?

推荐答案

Camel 中的 to 在运行时不会被解释.

The to in the Camel is not interpreted at runtime.

如果你想动态构建你的URI,你应该使用recipientList.请参阅 https:///camel.apache.org/manual/latest/faq/how-to-use-a-dynamic-uri-in-to.html

You should use recipientList if you want to construct your URI dynamically. See https://camel.apache.org/manual/latest/faq/how-to-use-a-dynamic-uri-in-to.html

相关文章