Spring 集成 Java DSL:远程过滤器未应用于 handle 方法

Spring Integration Java DSL: Remote filter is not applied on handle method

我想从 SFTP 服务器读取特定文件并且只获取一次压缩文件。 我在处理消息时遇到问题,因为在远程服务器上定义的过滤器似乎没有应用在 handle 方法中。

依赖关系:

    public IntegrationFlow buildSftpInboundIntegrationFlow() {
        return IntegrationFlows
                .from(
                        Sftp
                        .inboundStreamingAdapter(buildSftpRemoteFileTemplate())
                        .remoteDirectory(getRemoteDirectoryPath())
                        .filter(buildRemoteFileFilter())
                        .remoteFileSeparator(
                                Optional
                                .ofNullable(getRemoteFileSeparator())
                                .orElse(DEFAULT_REMOTE_PATH_SEPARATOR))
                        .maxFetchSize(
                                Optional.ofNullable(getMaxFetchSize()).orElse(DEFAULT_MAX_FETCH_SIZE)),
                        sourcePollingChannelAdapterSpec -> sourcePollingChannelAdapterSpec
                        .id(getSftpInboundStreamingAdapterIdentifier())
                        .autoStartup(true)
                        .poller(buildPollerSpec()))
                .handle(handleMessage())
                .get();
    }

    /**
     * Allows to build a regex to filter files.
     *
     * @return a regex as a {@link String}.
     */
    private String buildRegexFileFilter() {
        return String.format(".*\.%s", getFileExtensionToFilter());
    }

    /**
     * Allows to build an instance of {@link SftpRemoteFileTemplate}.
     *
     * @return an instance of {@link SftpRemoteFileTemplate}.
     */
    private SftpRemoteFileTemplate buildSftpRemoteFileTemplate() {
        final SftpRemoteFileTemplate sftpRemoteFileTemplate = new SftpRemoteFileTemplate(getSftpSessionFactory());
        sftpRemoteFileTemplate.setAutoCreateDirectory(true);

        return sftpRemoteFileTemplate;
    }

    /**
     * Allows to build the filters to apply to the remote files.
     *
     * @return an instance of {@link CompositeFileListFilter}.
     */
    @SuppressWarnings("resource")
    private CompositeFileListFilter<LsEntry> buildRemoteFileFilter() {
        return new ChainFileListFilter<LsEntry>() // NOSONAR
                .addFilters(
                        new SftpRegexPatternFileListFilter(buildRegexFileFilter()),
                        getSftpPersistentAcceptOnceFileListFilter());
    }

    /**
     * Allows to build the poller specifications.
     *
     * @return an instance of {@link PollerSpec}.
     */
    private PollerSpec buildPollerSpec() {
        return Pollers
                .fixedDelay(
                       Optional.ofNullable(getPollerDelayInSeconds()).orElse(DEFAULT_POLLER_DELAY_IN_SECONDS),
                        TimeUnit.SECONDS)
                .transactional()
                .transactionSynchronizationFactory(getTransactionSynchronizationFactory());
    }
...

你有什么想法可以给我建议吗? 为什么在 handle 方法中我收到应该被远程过滤器排除的文件? 这是一个错误?如何获得过滤消息?

这是版本 5.2.1 中模块 spring-integration 和 spring-integration-sftp 中的错误。 它通过在 5.2.2 版本中升级这些依赖项来工作。 (2019 年 12 月 6 日)