Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring integration Spring集成-FTP应与本地文件夹同步_Spring Integration_Spring Integration Sftp - Fatal编程技术网

Spring integration Spring集成-FTP应与本地文件夹同步

Spring integration Spring集成-FTP应与本地文件夹同步,spring-integration,spring-integration-sftp,Spring Integration,Spring Integration Sftp,我有ftp位置文件和本地文件夹,在第一次将文件复制到本地和重新启动服务器时(当前它正在将已复制的文件复制到本地文件夹),它不应查找本地已存在的文件,而应仅查找新文件。请告诉我是否可以使用Spring Integration ftp实现它? 我也添加了过滤器,但仍然不起作用,请告诉我哪里出了问题 @Bean @InboundChannelAdapter(value=“inputChannel”,poller=@poller(fixedDelay=“1000”,maxMessagesPerPoll=

我有ftp位置文件和本地文件夹,在第一次将文件复制到本地和重新启动服务器时(当前它正在将已复制的文件复制到本地文件夹),它不应查找本地已存在的文件,而应仅查找新文件。请告诉我是否可以使用Spring Integration ftp实现它? 我也添加了过滤器,但仍然不起作用,请告诉我哪里出了问题

@Bean
@InboundChannelAdapter(value=“inputChannel”,poller=@poller(fixedDelay=“1000”,maxMessagesPerPoll=“1”))
public MessageSource receive(){
FtpInboundFileSynchronizingMessageSource=new-FtpInboundFileSynchronizingMessageSource(synchronizer());
PropertiesPersistingMetadataStore metadataStore=新PropertiesPersistingMetadataStore();
FileSystemTempersistentAcceptonCefileListFilter acceptOnceFilter=新的FileSystemTempersistentAcceptonCefileListFilter(元数据存储,“*.xml”);
文件临时=新文件(临时文件夹);
metadataStore.setBaseDirectory(临时文件夹);
messageSource.setLocalDirectory(临时);
messageSource.setAutoCreateLocalDirectory(false);
messageSource.setLocalFilter(acceptOnceFilter);
返回消息源;
}
专用AbstractInboundFileSynchronizer同步器(){
folderCleanUp();
AbstractInboundFileSynchronizer fileSynchronizer=新的FtpInboundFileSynchronizer(sessionFactory());
fileSynchronizer.setRemoteDirectory(ftpFileLocation);
fileSynchronizer.setDeleteRemoteFiles(false);
Pattern=Pattern.compile(“.\\\.xml$”);
FTPregExpaterFileListFilter FTPregExpaterFileListFilter=新的FTPregExpaterFileListFilter(模式);
setFilter(ftpregregaterFileListFilter);
返回文件同步器;
}

是的,是的。查看
localfilter
属性和
filesystemtempersistentaptoncefilelistfilter
可供您通过外部
元数据存储来跟踪本地文件,例如Redis、MongoDb或在系统重新启动时保留数据的任何其他文件。

要澄清如何实现自定义
FileListFilter
,以下是此类筛选器的示例(旨在筛选出比给定时间更早的文件):

@组件
公共类OldFileFilter扩展了AbstractFileListFilter{
//(oldFilesTimestamp字段声明及其源)
@凌驾
受保护的布尔接受(FTPFile文件){
字符串文件名=file.getName();
long fileTimestamp=file.getTimestamp().getTimeInMillis();
ZonedDateTime fileModTimestamp=ZonedDateTime.ofInstant(Instant.ofEpochMilli(fileTimestamp),ZoneId.systemDefault());
布尔值isFileAcceptable=fileModTimestamp.isAfter(OldFileTimestamp);
if(log.isTraceEnabled()){
log.trace(“文件{}:\n”+
“文件时间戳:{};\n”+
“给定的时间戳:{};\n”+
“文件是新的:{}”,
fileName、fileModTimestamp、oldfiletimestamp、isFileAcceptable);
}
退货是可以接受的;
}
}
还请注意,Spring集成允许对单个文件源同时应用多个过滤器。这可以通过
CompositeFileListFilter
实现:

private CompositeFileListFilter remoteFileFilter(){
FTPPersistentAcceptonFileListFilter persistentFilter=
新的FtpPersistentAcceptOnceFileListFilter(元数据存储,“remoteProcessedFiles”);
返回新的CompositeFileListFilter(Arrays.asList(新的FtpSimplePatternFileListFilter(“*.zip”),
persistentFilter,
oldFilesFilter/*从前面的示例中已知*/);
}

无论使用何种过滤器,都不会再次复制本地目录中已有的文件;看见本地筛选器需要持久化,以防止重新启动后已处理的文件发出消息。感谢Artem,我已添加了上述筛选器代码,但仍然不起作用。其他任何东西都需要doneThanks@GaryRussell,我需要复制同一个文件(已复制到本地文件)如果有来自ftp的数据被修改和替换,并且如果我尝试重新启动服务器,所有内容都会复制到本地。而不是我只需要复制更改文件并替换本地文件,即使不重新启动服务器。请让我知道我应该做什么。在这种情况下,您必须在处理后删除本地文件。否则它将不会重新同步。无论如何,保存磁盘是个好主意。但是使用持久性过滤器是至关重要的谢谢@GaryRussell,我使用的是FileUtils.forceDelete(新文件(“temp”);要删除文件夹,如果我复制并处理了它,如果它被删除,它将再次拉取相同的文件,这将是一个链进程。一旦系统重新启动,它将被删除。我需要,即使系统正在运行,它也应该识别用相同名称修改的文件,并且应该选择用于处理。请告诉我是否可以使用spring ftp集成