如何处理具有Spring Integration的大型ZIP文件的副本

发布于 2025-01-31 15:44:06 字数 1875 浏览 1 评论 0原文

该主题类似于:从ftp 但是没有明确的答案,这里的情况并不完全相同。

我在一台服务器上有一个输入目录,该目录将从另一台远程服务器复制到zip文件中。基本上,文件是由外部文件同步工具复制的(在服务器a上的源dir到服务器b上的目的地DIR之间),但也可以通过SCP或FTP工具复制用于测试目的。

通过以这种方式处理ZIP文件,通过Spring Integration Zip模块处理:

@Bean
public IntegrationFlow zipFilePollingFlow(
        @Value("file:///${zip.inputDir}") File in,
        UnZipTransformer unzipTransformer,
        UnZipResultSplitter unZipResultSplitter,
        TransactionManager pseudoTransactionManager) {

    FileInboundChannelAdapterSpec inbound = Files.inboundAdapter(in).autoCreateDirectory(true);

    return IntegrationFlows.from(inbound, pm -> pm.poller(p -> p.fixedDelay(5000)
                .transactionSynchronizationFactory(zipIntegrationTxSynchronizationFactory())
                    .transactional(pseudoTransactionManager))) // Zip process is done transactionnaly
            .handle(fileCleanService) // Deletes files in another directory
            .transform(unzipTransformer)
            .split(unZipResultSplitter)
            .<File, Boolean>route( ... ) // the rest of the flow
            .get();
}

小ZIP文件一切都很好。但是,当复制/传输大文件(数百MB)时,我们陷入了此错误:

osintegration.handler.logginghandler:org.springframework.integration.trementer.trementer.messagetransformationException:无法转换消息;嵌套异常是org.springframework.messaging.messagehandlingexception:无法应用zip变换。嵌套例外是Java.lang.IlgalStateException:不是zip文件:/.../ temp/extract/zip/zip/full-extract-rev.zip

由:org.springframework.messaging.messagehandlingexception:无法应用zip变换。嵌套例外是Java.lang.illegalstateException:不是zip文件:....

我们如何使用Spring Integration正确处理和处理大型ZIP文件? ZIP文件变压器是否有可能重试该过程,直到源zip文件的传输完成?

This topic is similar to : Spring integration problem when reading file from ftp
but there is no clear answer and the scenario here is not exactly the same.

I have an input directory on a server where zip files are copied into from another remote server. Basically files are copied by an external file synchronization tool (between a source dir on server A to the destination dir on server B), but could also be copied by scp or ftp tools for test purposes.

The zip files are processed by Spring Integration Zip module this way :

@Bean
public IntegrationFlow zipFilePollingFlow(
        @Value("file:///${zip.inputDir}") File in,
        UnZipTransformer unzipTransformer,
        UnZipResultSplitter unZipResultSplitter,
        TransactionManager pseudoTransactionManager) {

    FileInboundChannelAdapterSpec inbound = Files.inboundAdapter(in).autoCreateDirectory(true);

    return IntegrationFlows.from(inbound, pm -> pm.poller(p -> p.fixedDelay(5000)
                .transactionSynchronizationFactory(zipIntegrationTxSynchronizationFactory())
                    .transactional(pseudoTransactionManager))) // Zip process is done transactionnaly
            .handle(fileCleanService) // Deletes files in another directory
            .transform(unzipTransformer)
            .split(unZipResultSplitter)
            .<File, Boolean>route( ... ) // the rest of the flow
            .get();
}

Everything is fine with small zip files. However when large files are copied/transferred (hundred of MBs), we are falling in this error :

o.s.integration.handler.LoggingHandler : org.springframework.integration.transformer.MessageTransformationException: failed to transform message; nested exception is org.springframework.messaging.MessageHandlingException: Failed to apply Zip transformation.; nested exception is java.lang.IllegalStateException: Not a zip file: /.../temp/extract/zip/full-extract-rev.zip

Caused by: org.springframework.messaging.MessageHandlingException: Failed to apply Zip transformation.; nested exception is java.lang.IllegalStateException: Not a zip file: ....

How can we handle and process correctly large zip files with Spring Integration ? Would it be possible for the Zip file transformer to retry the process until the transfer of the source zip file is complete ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南冥有猫 2025-02-07 15:44:06

替代方法是配置fileInboundChannelAdaptersPec lastModifiedFilelistFilter

 * The {@link FileListFilter} implementation to filter those files which
 * {@link File#lastModified()} is less than the {@link #age} in comparison
 * with the current time.

因此,它只能在足够旧时传递文件。

您还需要将此过滤器与acceptoncefilelistfilter组合到chainfilelistfilter中,以避免一次又一次地读取相同的文件。

不确定是否有选项在文件系统上配置目录以仅让对文件的独家访问(默认情况下它在Windows上)打开文件。如果我们失败了,我们不会在codefilelistfilter中向文件路径路径, /Docs/current/Referent/html/file.html#file-reading“ rel =” nofollow noreferrer“> https://docs.spring.io/spring.io/spring-integration/docs/docs/docs/current/current/current/referent/referent/reference/reference/html/file.htmll/文件阅读

The alternative is to configure that FileInboundChannelAdapterSpec with a LastModifiedFileListFilter:

 * The {@link FileListFilter} implementation to filter those files which
 * {@link File#lastModified()} is less than the {@link #age} in comparison
 * with the current time.

So, it will let the file to pass only when it is old enough.

You also need to combine this filter with an AcceptOnceFileListFilter into a ChainFileListFilter to avoid reading the same file again and again.

Not sure if there is an option to configure a directory on file system to let only an exclusive access to the file (well, it is there on Windows by default), so then we would be able to write a custom filter with an attempt to open the file. If we fail, we don't path the file down to AcceptOnceFileListFilter in the ChainFileListFilter: https://docs.spring.io/spring-integration/docs/current/reference/html/file.html#file-reading

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文