使用 Spring 和 Hibernate 从 SFTP 获取大文件并存储在 Postgresql 中的问题

Problems in fetching large file from SFTP and storing in Postgresql using Spring and Hibernate

我有 Spring 集成管道,它从 SFTP 服务器获取文档并将其保存到 Postgresql 数据库(由 Spring data/hibernate 完成)。成功后 sftp 获取管道获取文件名和内容(如 byte[])并将其保存到数据库。

我有两个主要问题:

  1. 问题是我没有预料到客户端会上传 100Mb - 200MB 的 zip 文件,管道读取但无法持久化。

  2. 有时 (不总是) "java.lang.OutOfMemoryError: Java heap space" 被抛出, 但是增加堆内存暂时解决了这个问题,也许有 不需要将整个文件内容加载到内存的解决方案 在持久化到数据库之前?

仅记录事务期间记录的消息:

"thread":"task-scheduler-8","location":"org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.copyFileToLocalDirectory(AbstractInboundFileSynchronizer.java:430)","level":"WARN","message":"The remote file '-r-x------ 1 0        0           81062125 May 15 15:06 test.zip' has not been transferred to the existing local file './transfered-files/test.zip'. Consider removing the local file."}

我明白我应该分享代码,但我真的不能(法律问题)。

考虑在本地文件系统上使用 SftpStreamingMessageSource 而不是 copy/paste:https://docs.spring.io/spring-integration/docs/current/reference/html/#sftp-streaming