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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16222720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:17:01  来源:igfitidea点击:

Use Exchange Property in Camel DSL "to"

javaapache-camel

提问by dev

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:

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

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

The file is being saved as:

该文件被保存为:

"file-property{uid}.xml" though

My processor is as follows:

我的处理器如下:

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

关于可能出现什么问题或我如何实现这一目标的任何想法?

采纳答案by Ben Goldin

The toin the Camel is not interpreted at runtime.

to在骆驼不会在运行时解释。

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

如果要动态构建 URI,则应使用收件人列表。见https://camel.apache.org/manual/latest/faq/how-to-use-a-dynamic-uri-in-to.html

回答by dev

UPDATEDNew answer accepted above instead of this previous one:

上面接受了更新的新答案,而不是以前的答案:



The answer is [was]:

答案是[是]:

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

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

This simple expression pulls in the exchange property. For a complete list of what you can pull in, see the Simple Expression Language Reference

这个简单的表达式引入了交换属性。有关您可以引入的内容的完整列表,请参阅简单表达式语言参考