文件传输中途时,Spring Integration侦听器会拾取文件吗?

时间:2019-02-11 01:13:34

标签: spring spring-integration listener sftp inbound

美好的一天,

我正在使用Spring Integration 2.2将侦听器构建到文件夹。我可以知道在文件传输中途传输时,我的收听者将如何检查我的文件?还是要等到完整的文件传输完毕?

假设有一个10MB的txt文件,但是由于互联网速度缓慢,该文件需要10秒才能传输到该文件夹​​。假设在第5秒,文件只完成了传输5MB,还剩下5MB,可能是听者去接了文件并处理了吗?

这是xml中我的侦听器代码的一部分:

<int-file:inbound-channel-adapter id="hostFilesIn" directory="${hostfile.dir.in}" 
         prevent-duplicates="true"  filename-regex="${hostfile.in.filename-regex}">
        <int:poller id="poller" fixed-rate="${poller.fixrate:15000}" max-messages-per-poll="1" />
    </int-file:inbound-channel-adapter>

让我知道是否需要更多信息。

这是发生的问题:

从日志中,我们可以看到文件正在添加到队列中,

2019-02-01 11:13:33.011 [task-scheduler-9] DEBUG org.springframework.integration.file.FileReadingMessageSource - Added to queue: [/apps/NAS/ftp/in/incompleteL041.TXT]

之后,出现以下错误:

2019-02-01 11:13:33.096 [task-scheduler-9] DEBUG c.c.c.c.g.a.auditservice.SimpleErrorIdResolver - ERROR MESSAGE7 : 
java.io.FileNotFoundException: /apps/NAS/ftp/in/incompleteL041.TXT (A file or directory in the path name does not exist.)

这是因为,当文件完成传输后,它将重命名为L041.TXT。

请告知。

1 个答案:

答案 0 :(得分:0)

您的理解是完全正确的。这就是文件系统的行为。如果文件已经存在,即使它仍处于写入模式,它对于包括提到的文件读取消息源在内的所有其他文件都是可见的。

要防止读取未完成的文件,当未完成的文件具有不同的名称并且文件入站通道适配器上的过滤器应配置为看不到该文件的方式时,您确实需要实现逻辑。 / p>

类似这样的正则表达式function clearFilter() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var ssId = ss.getId(); var sheetId = ss.getActiveSheet().getSheetId(); var requests = [{ "clearBasicFilter": { "sheetId": sheetId } }]; Sheets.Spreadsheets.batchUpdate({'requests': requests}, ssId); } 应该可以为您提供最新的解释。