我当前的项目是基于spring集成的。我用springboot开发这个项目。
我的目标是使用spring集成来完成以下任务。
连接到sftp
检查是否在本地文件夹中的特定文件夹中创建了目录
检查特定于(csv&xlsx)的文件的合格文件扩展名
将所有内容从sftp远程目录下载到本地目录&需要跟踪文件传输开始时间和文件传输结束时间。
逐行从本地目录中读取文件并提取特定的列信息。
你能给我一些建议吗?
我怎样才能得到换乘开始时间?注意:这个需求我必须作为restapi开发。请提供一些指导,我如何通过使用spring集成来实现这一点?
谢谢。:)
public class SftpConfig {
@Value("${sftp.host}")
private String sftpHost;
@Value("${sftp.port:22}")
private int sftpPort;
@Value("${sftp.user}")
private String sftpUser;
@Value("${sftp.password:#{null}}")
private String sftpPasword;
@Value("${sftp.remote.directory:/}")
private String sftpRemoteDirectory;
@Value("${sftp.privateKey:#{null}}")
private Resource sftpPrivateKey;
@Value("${sftp.privateKeyPassPhrase:}")
private String privateKeyPassPhrase;
@Value("${sftp.remote.directory.download.filter:*.*}")
private String sftpRemoteDirectoryDownloadFilter;
@Value("${sftp.remote.directory.download:/}")
private String sftpRemoteDirectoryDownload;
@Value("${sftp.local.directory.download:${java.io.tmpdir}/localDownload}")
private String sftpLocalDirectoryDownload;
/*
* The SftpSessionFactory creates the sftp sessions. This is where you define
* the host , user and key information for your sftp server.
*/
// Creating session for Remote Destination SFTP server Folder
@Bean
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(sftpHost);
factory.setPort(sftpPort);
factory.setUser(sftpUser);
if (sftpPrivateKey != null) {
factory.setPrivateKey(sftpPrivateKey);
factory.setPrivateKeyPassphrase(privateKeyPassPhrase);
} else {
factory.setPassword("sftpPassword");
}
factory.setAllowUnknownKeys(true);
return new CachingSessionFactory<ChannelSftp.LsEntry>(factory);
}
/*
* The SftpInboundFileSynchronizer uses the session factory that we defined above.
* Here we set information about the remote directory to fetch files from.
* We could also set filters here to control which files get downloaded
*/
@Bean
public SftpInboundFileSynchronizer SftpInboundFileSynchronizer () {
SftpInboundFileSynchronizer synchronizer = new SftpInboundFileSynchronizer();
return null;
}
1条答案
按热度按时间yrdbyhpb1#
如果你看看
SftpStreamingMessageSource
取而代之的是:https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-流媒体,加上使用FileSplitter
要逐行读取该文件(也支持“first like as header”),您不必担心将文件传输到local dir。您将按需使用远程内容完成所有操作。另一方面,既然您谈到restapi,您可能会有一些
@RestController
或spring集成http入站网关:https://docs.spring.io/spring-integration/docs/current/reference/html/http.html#http-入站时,则需要考虑使用SftpOutboundGateway
带着一个MGET
命令:https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-出站网关。如果仍然需要跟踪每个文件的下载时间,则需要考虑使用该网关两次:使用
LIST
指挥与控制NAME_ONLY
,第二次是GET
命令。此时您可以添加ChannelInterceptor
为了input
以及output
第二个网关的通道,因此您将有一个文件名信息来关联并捕获该网关前后的开始和停止时间。