带有 doneFileName 的 Apache 骆驼文件 [英] Apache camel file with doneFileName

查看:31
本文介绍了带有 doneFileName 的 Apache 骆驼文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始研究 apache camel(使用蓝图路线),但我已经被卡住了.

我需要处理一组不同格式的 csv 文件.我得到 5 个带有 foo_X_20160110.csv 的文件,其中 X 指定了 csv 文件的类型,并且这些文件有一个日期戳.这些文件可能非常大,因此一旦写入所有文件,就会写入完成"文件.完成的文件名为 foo_trigger_20160110.csv.

我已经看到文件上的 doneFileName 选项,但它只支持静态名称(我在文件名中有一个日期),或者它希望每个输入文件都有一个完成的文件.

文件必须按固定顺序处理,但不能保证它们以何种顺序写入输入目录.因此我需要等待完成的文件.

知道如何用 Camel 做到这一点吗?

有什么好的骆驼书推荐吗?

解决方案

这里是文档中的一个例子http://camel.apache.org/file2.html

from("file:C:/temp/input.txt?doneFileName=done");

如你所见,doneFileName 有一个静态值done".但是您可以使用标准 java 编写动态名称,即用于当前日期格式或其他任何内容,只需使用字符串操作来构造 URI.希望有所帮助.

更新:

顺便说一下,正如文档中提到的,doneFileName 可以选择动态占位符.

<块引用>

然而,更常见的是每个目标文件有一个完成的文件.这个意味着存在 1:1 的相关性.为此,您必须使用动态doneFileName 选项中的占位符.目前 Camel 支持以下两个动态标记:file:name 和 file:name.noext,它们必须括在 ${ } 中.消费者只支持静态部分done 文件名作为前缀或后缀(不能同时使用).

from("file:bar?doneFileName=${file:name}.done");

<块引用>

您也可以为完成的文件使用前缀,例如:

from("file:bar?doneFileName=ready-${file:name}");

I am just starting to look at apache camel (Using blueprint routes) and I am already stuck.

I need to process a set of csv files with different formats. I get 5 files with foo_X_20160110.csv were X specifies the type of csv file and the files have a date stamp . These files can be quite large so a 'done' file is written once all files are written. The done file is named foo_trigger_20160110.csv.

I've seen the doneFileName option on file but that only supports a static name (I have a date in the filename) or it expects a done file for each input file.

The files have to be proceeded in a fixed order but it is not guaranteed in which order they are written to the input directory. Hence I need to wait for the done file.

Any idea how this can be done with Camel?

Any suggestions for good Camel books?

解决方案

Here is an example from the documentation http://camel.apache.org/file2.html

from("file:C:/temp/input.txt?doneFileName=done");

As you can see the doneFileName has a static value "done". But you can use standard java to write dynamic names i.e. for current dateformat or anything else and just use string operation to construct the URI. Hope that helps.

Update:

By the way, as mentioned in the documentation there is the option of dynamic placeholders for the doneFileName.

However its more common to have one done file per target file. This means there is a 1:1 correlation. To do this you must use dynamic placeholders in the doneFileName option. Currently Camel supports the following two dynamic tokens: file:name and file:name.noext which must be enclosed in ${ }. The consumer only supports the static part of the done file name as either prefix or suffix (not both).

from("file:bar?doneFileName=${file:name}.done");

You can also use a prefix for the done file, such as:

from("file:bar?doneFileName=ready-${file:name}");

这篇关于带有 doneFileName 的 Apache 骆驼文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆