FTP Integration Flow筛选器在Spring Integration 5.0.0.RC1中不起作用



我已经将集成流从4.3.12升级到5.0.0.RC1,以利用入站流功能。我发现patternFilter和regexFilter根本没有过滤。为了检查它是否不仅仅是流媒体接口,我尝试了基于文件的接口,我看到了同样的结果。

在4.3.12中,我的基于文件的流定义为:

return IntegrationFlows
.from(s -> s.ftp(ftpSessionFactory())
.preserveTimestamp(true)
.remoteDirectoryExpression(remoteDirectory())
.regexFilter("sn\.[0-9]{4}\.txt$")
.filter(ftpPersistantFilter())
.localFilter(fileSystemPersistantFilter())
.localFilename(f -> (currentUtcDay.toString("YYYYMMdd")) + "." + f)
.localDirectory(new File(this.localDirectory)),
e -> e.id("ftpInboundAdapter").autoStartup(true))
.channel(MessageChannels.queue("ftpInboundResultChannel"))
.get();

为了保持一致性,这里有5.0.0中相同的定义。RC1:

return IntegrationFlows
.from(Ftp.inboundAdapter(ftpSessionFactory())
.preserveTimestamp(true)
.remoteDirectoryExpression(remoteDirectory())
.regexFilter("sn\.[0-9]{4}\.txt$")
.filter(ftpPersistantFilter())
.localFilter(fileSystemPersistantFilter())
.localFilename(f -> (currentUtcDay.toString("YYYYMMdd")) + "." + f)
.localDirectory(new File(this.localDirectory)),
e -> e.id("ftpInboundAdapter").poller(Pollers.fixedDelay(100)))
.channel(MessageChannels.queue("ftpInboundResultChannel"))
.get();

它在5.0.0.RC1中根本没有过滤。过滤器的配置是否已更改?我还有什么需要做的吗?

编辑:对于下一个遇到这种情况的人,以下是解决方法。

return IntegrationFlows
.from(Ftp.inboundAdapter(ftpSessionFactory())
.preserveTimestamp(true)
.remoteDirectoryExpression(remoteDirectory())
.filter(ftpPersistantFilter())
.localFilter(fileSystemPersistantFilter())
.localFilename(f -> (currentUtcDay.toString("YYYYMMdd")) + "." + f)
.localDirectory(new File(this.localDirectory)),
e -> e.id("ftpInboundAdapter").poller(Pollers.fixedDelay(100)))
.channel(MessageChannels.queue("ftpInboundResultChannel"))
.get();

然后我将ftpPersistentFilter从:更改为

@Bean
public FtpPersistentAcceptOnceFileListFilter ftpPersistantFilter() {
return new FtpPersistentAcceptOnceFileListFilter(metadataStore(), "ftpPersistentAcceptOnce");
}

至:

@Bean
public CompositeFileListFilter ftpPersistantFilter() {
CompositeFileListFilter filters = new CompositeFileListFilter();
filters.addFilter(new FtpPersistentAcceptOnceFileListFilter(metadataStore(), "ftpPersistentAcceptOnce"));
filters.addFilter(new FtpRegexPatternFileListFilter(regexFilter));
}

Spring Integration5.0中的更改类似于.filter(ftpPersistantFilter())完全覆盖以前的过滤器感知选项:

/**
* Configure a {@link FileListFilter} to be applied to the remote files before
* copying them.
* @param filter the filter.
* @return the spec.
*/
public S filter(FileListFilter<F> filter) {
this.synchronizer.setFilter(filter);
return _this();
}

因此,您的.regexFilter("sn\.[0-9]{4}\.txt$")将被忽略。

这样做是为了避免与意外的内部组成混淆。例如,CCD_ 4和CCD_ 5滤波器与CCD_https://docs.spring.io/spring-integration/docs/5.0.0.RC1/reference/html/whats-new.html#__s_ftp_changes:

所有入站通道适配器(基于流和同步)现在默认使用适当的AbstractPersistentAcceptOnceFileListFilter实现,以防止远程文件重复下载。

换句话说:任何基于过滤器的选项都是互斥的,最后一个获胜。这是一个更容易支持的选项,让最终用户不必担心意外的突变。

要解决您的需求,您必须将CompositeFileListFilter用于ftpPersistantFilterFtpRegexPatternFileListFilter

我认为我们必须在这个问题上添加一些迁移指南项目符号。谢谢你的理解。

最新更新