Use Exchange Property in Camel DSL “to”

旧城冷巷雨未停 提交于 2019-12-10 15:32:36

问题


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

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?


回答1:


The to in the Camel is not interpreted at runtime.

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




回答2:


UPDATED New answer accepted above instead of this previous one:


The answer is [was]:

.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



来源:https://stackoverflow.com/questions/16222720/use-exchange-property-in-camel-dsl-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!