Apache camel apachecamel-JsonPath&;唯一文件名
骆驼2.13.0 我试图使用一个包含多条记录的json字符串,并为每条记录生成一个输出文件Apache camel apachecamel-JsonPath&;唯一文件名,apache-camel,Apache Camel,骆驼2.13.0 我试图使用一个包含多条记录的json字符串,并为每条记录生成一个输出文件 public void configure() { from("file:data/input") // my bean splits the input string and returns a json string via Gson .bean(new com.camel.Tokenizer(), "getSentences") .split(
public void configure() {
from("file:data/input")
// my bean splits the input string and returns a json string via Gson
.bean(new com.camel.Tokenizer(), "getSentences")
.split(new JsonPathExpression("$[*]"))
.convertBodyTo(String.class)
.to("file:data/output");
}
}
样本输入:
“这是字符串1。这是字符串2。”
如果我按原样运行上面的代码,就会得到一个包含“thisisstring#2”的输出文件。如果删除.split()调用,我会得到一个包含json的输出文件,正如预期的那样:
[
{
"token": "This is string #1."
},
{
"token": "This is string #2."
}
]
如何实现表示两行数据的两个输出文件
我突然想到,可能分割工作正常,第二个输出文件覆盖了第一个输出文件。根据文档,如果没有设置CamelFileName,默认行为是创建一个唯一的生成ID,但我没有遇到过这种情况。在我的例子中,输出文件名始终与输入文件名匹配
如何在每个文件夹中获得唯一的文件名
谢谢 终于找到了合适的搜索词,并找到了以下有用的帖子: 诀窍是在.to()中使用一点逻辑来实现唯一的输出文件名:
.to("file:data/sentence_q?fileName=${header.CamelSplitIndex}.txt");
JsonPathExpression就像一个符咒一样工作,不需要处理器()或解组器(),就像我之前尝试的那样